redplanetlabs / specter

Clojure(Script)'s missing piece
Apache License 2.0
2.51k stars 102 forks source link

Is there a way of selecting unique values of a particular key out of a list of maps? #285

Closed dmg46664 closed 4 years ago

dmg46664 commented 4 years ago

I'm learning clojure so perhaps this is something that is not an intended use case of specter, and best left to core implementations. It would be useful for me if non-supported use cases were added to the cheat sheet, if for no other reason than for clarity 🙏

I know there is pred but this would need to be a stateful predicate I guess, which doesn't feel very idiomatic.

dmg46664 commented 4 years ago

Ah. Never mind, I see it's just a matter of pulling the values and wrapping the outside with distinct, which I just learnt about.

(distinct (select [ALL :key] col))

I guess if you wanted the entire map of each first distinct item that might be an interesting use case, but it's not mine. Closing.