Skip to content
Permalink
Browse files

CLJS-3199: Interop with JavaScript's iterable objects via Iterator pr…

…otocol

Move es6-iterator-seq declare. Add js-iterable? predicate. Add case to seq.
  • Loading branch information
swannodette committed Jan 9, 2020
1 parent 23cedec commit dcc8e61c79bfc701fe9e1414fe5db93edf6f1853
Showing with 11 additions and 2 deletions.
  1. +11 −2 src/main/cljs/cljs/core.cljs
@@ -1192,6 +1192,11 @@
[x]
(satisfies? IIterable x))

(defn js-iterable?
"Return true if x has a JavaScript iterator property"
[x]
(gobject/containsKey x ITER_SYMBOL))

(defn clone
"Clone the supplied value which must implement ICloneable."
[value]
@@ -1202,6 +1207,8 @@
[value]
(satisfies? ICloneable value))

(declare es6-iterator-seq)

(defn ^seq seq
"Returns a seq on the collection. If the collection is
empty, returns nil. (seq nil) returns nil. seq also works on
@@ -1220,6 +1227,10 @@
(when-not (zero? (.-length coll))
(IndexedSeq. coll 0 nil))

(js-iterable? coll)
(es6-iterator-seq
(.call (gobject/get coll ITER_SYMBOL) coll))

(native-satisfies? ISeqable coll)
(-seq coll)

@@ -1291,8 +1302,6 @@
[coll]
(ES6Iterator. (seq coll)))

(declare es6-iterator-seq)

(deftype ES6IteratorSeq [value iter ^:mutable _rest]
ISeqable
(-seq [this] this)

0 comments on commit dcc8e61

Please sign in to comment.
You can’t perform that action at this time.