This one has been bothering me for a while now, How should we store a value in a set or map in a for loop?
(let [s #{}]
(for [ i (range 10)
j (range 10) ]
(into s [i j])))
i know this will not work, but i want a functionality similar to this , where the set will finally contain [0 0] [0 1]...[0 9] [1 0]...[9 9]
Thanks
If I understand your question correctly you need to turn your expression inside-out:
(let [s #{}]
(into s (for [i (range 10)
j (range 10)]
[i j])))
The thing to realize here is that for
returns a value (a lazy sequence) unlike for-loops in more imperative languages like Java and C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With