Welcome! Please see the About page for a little more info on how this works.

+2 votes
in Docs by

Looking at the source of distinct in both Clojure and Clojurescript, it seems that the order of the first appearance of distinct elements is preserved. If this is a promise of distinct, it would be good have it documented in the doc string. I am personally relying on this behavior for sorting a collection of maps based on the order of which certain keys appear in the collection.

1 Answer

+1 vote
selected by
Best answer

I don't think we want to say more than it says. If you pass a sequence or sequential collection, then it returns a "sequence of the elements" - it seems natural to expect the sequential elements to be returned in the same order.

On the flip side, if the coll passed to distinct is unordered and not sequential (ie a map or set), this function cannot make promises about the order of the results.

It is also intentionally ambiguous which equal element you will get in the result (but again, the first in a sequential coll seems like the obvious answer).

Yes, makes sense regarding maps and sets. Thanks!
The strongest hint is that API doc says, "Returns a lazy sequence...".