Fork me on GitHub
#cljs-dev
<
2019-11-25
>
Roman Liutikov16:11:12

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.))

lilactown17:11:16

extending the seq abstraction to iterables would be pretty cool

Alex Miller (Clojure team)17:11:16

oh, this is cljs, nvm! :)

Roman Liutikov17:11:45

there’s es6-iterator-seq indeed

Roman Liutikov17:11:27

but since Clojure already works with Java collections maybe cljs should be on par as well

souenzzo17:11:46

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))

Roman Liutikov17:11:36

@souenzzo For array-like collections in js one can use cljs.core/array-seq

Roman Liutikov18:11:35

iterables are different, though many array-like collection types in browser env might have been already upgraded to iterator protocol (Array for sure)

thheller20:11:57

@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.

lilactown20:11:59

Could do existence checks

thheller20:11:46

that doesn't play well with :advanced

Roman Liutikov21:11:16

Maybe it's fine to include this code even if it's not used

dnolen21:11:46

@roman01la there's no specific reason other than it hasn't been requested - I think it just means adding a new branch to seq

dnolen21:11:30

we don't care about the specific types of course - just whether it's iterable - has "@@iterator" property or the actual iterator symbol

dnolen22:11:55

@thheller re: var lifting support - I think that's definitely not something we intend to support in any direct kind of way.

thheller22:11:46

it would let reify generate better code but I guess that doesn't matter much

dnolen22:11:45

yeah - not a pressing a concern