Shouldn’t cljs interop with iterable JS objects such as Set
and Map
via iterator protocol? So (first (js/Set. #js [1 2 3])) ;; 1
would be possible. Clojure allows (first (HashSet.))
extending the seq abstraction to iterables would be pretty cool
iterator-seq
oh, this is cljs, nvm! :)
there’s es6-iterator-seq
indeed
but since Clojure already works with Java collections maybe cljs should be on par as well
There is some really wired lists like https://developer.mozilla.org/en-US/docs/Web/API/FileList that for me just works with (for [i (range (.-length x))] (aget x i))
@souenzzo For array-like collections in js one can use cljs.core/array-seq
iterables are different, though many array-like collection types in browser env might have been already upgraded to iterator protocol (Array for sure)
@roman01la the issue is that CLJS in theory generates ES3 code. that didn't have Map/Set, so if the protocols were extended onto those it wouldn't be ES3 anymore. not sure that it should either. could do it in a simple library.
Could do existence checks
that doesn't play well with :advanced
Maybe it's fine to include this code even if it's not used
@roman01la there's no specific reason other than it hasn't been requested - I think it just means adding a new branch to seq
Submitted a patch https://clojure.atlassian.net/browse/CLJS-3199
we don't care about the specific types of course - just whether it's iterable - has "@@iterator"
property or the actual iterator symbol
@thheller re: var lifting support - I think that's definitely not something we intend to support in any direct kind of way.
it would let reify
generate better code but I guess that doesn't matter much
yeah - not a pressing a concern