What is an idiomatic way to convert a sequence to a set in Clojure? E.g what do I fill in at the dots?
(let s [1 1 2 2 3 3]
...)
So that it produces:
#{1 2 3}
I come up with:
(let [s [1 1 2 2 3 3]]
(loop [r #{} s s]
(if (empty? s) r (recur (conj r (first s)) (rest s)))))
But that seems not the way to go? Is there a function already that does this?
most collections have a function that produces them form anything seqable:
(set [1 1 2 2 3 3])
#{1 2 3}
for more interesting cases the into
function is good to know about:
(into #{1} [2 2 3 3])
#{1 2 3}
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