Fork me on GitHub
#clojure-dev
<
2019-01-24
>
borkdude15:01:50

Would it make sense to extend the for macro with an :into option, like some spec operators have? This way it could build a collection without first having to build a lazy seq

gfredericks21:01:33

I can't think of any objections on "that wouldn't work" or "isn't useful" grounds probably only "might look weird" or "not a good enough reason to change anything"

hiredman21:01:32

I suspect you would better servered by a version of for that produces an eduction

borkdude21:01:26

I went through a heap of 4clojure code today and I saw lot of (set (for ...)) calls, that gave me the idea

hiredman21:01:17

the thing with for is, seqs are a universal iteration protocol, so for can take a bunch of input collections, and iterate over them lazily by consuming seqs

hiredman21:01:50

a new version of for, not tied to seqs, would need some new iteration protocol for consuming collections

hiredman21:01:03

reduce is maybe the best bet for that

hiredman21:01:55

so you would have a for macro that generates a transducer with a source collection packaged together in an eduction

borkdude21:01:08

that would be awesome

cfleming22:01:02

cgrandโ€™s xforms has a transducing cousin of for.

borkdude22:01:29

wow, thanks! ๐Ÿ™‚

borkdude22:01:31

(into #{} (x/for [i % :when (even? i)] i) [1 1 2 3 3 3 4 4])
=> #{4 2}
๐Ÿ˜Ž