I have a sequence and trying to remove duplicates
case 1:
(vec (into #{} [1 1 2 2 3 3])) ; => [1 2 3]
case 2:
(distinct [1 1 2 2 3 3]) ; => [1 2 3]
As for differences, jas covered most of them in his comment:
distinct is lazydistinct with no arguments is a transducerdistinct maintains orderAs for which one is preferred, distinct is for the above reasons, but also because it explains what you need. I forget which Lisp book talked about this (might have been Let Over Lambda), but when given the choice between two similar functions, prefer the one that's more specific. distinct explains that you want distinct elements. (into #{} xs) might produce distinct values, but it also allows your intent to be misunderstood. Someone could easily think you wanted a set for some reason. distinct narrows down the why.
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