My version of distinct-by just took clojure.core/distinct and added a keyfn
(and optional max-n). It's hard to claim this code is readable. I took this
approach mostly because I knew it would be unlikely to be buggy, since it
was a simple change or two from clojure.core/distinct
(defn distinct-by
Yes, I find that much clearer too. Thanks!
On Saturday, July 22, 2017 at 4:50:23 PM UTC-4, tbc++ wrote:
>
> If we think about what we're doing here is a stateful filter, then maybe
> we could leverage a few more core Clojure functions:
>
>
> (defn distinct-by [f coll]
> (let [seen (atom #{})]
Perhaps you want to study the implementation in Medley, those are always
very good quality:
https://github.com/weavejester/medley/blob/254989ed3de83c30ce0101d66c7ce1b6ee257b4d/src/medley/core.cljc#L173
David
--
You received this message because you are subscribed to the Google
Groups "Clojure"
If we think about what we're doing here is a stateful filter, then maybe we
could leverage a few more core Clojure functions:
(defn distinct-by [f coll]
(let [seen (atom #{})]
(filter (fn [itm]
(let [m (f itm)]
(when-not (@seen m)
(swap!