adding arities to frequencies and distinct?

96 views
Skip to first unread message

Alex Baranosky

unread,
Jun 5, 2015, 12:27:25 PM6/5/15
to cloju...@googlegroups.com
I've got some utilities that I use occasionally that are built off of distinct and frequencies.

Does anyone think it makes sense to add extra arities to these fns in clojure.core to support this?

(defn frequencies
  "Returns a map from distinct items in coll to the number of times
  they appear."
  {:added "1.2"
   :static true}
  ([coll]
     (frequencies identity coll))
  ([keyfn coll]
     (persistent!
      (reduce (fn [counts x]
                (let [x' (keyfn x)]
                  (assoc! counts x' (inc (get counts x' 0)))))
              (transient {})
              coll))))

And then a similar change for clojure.core/distinct.

Ghadi Shayban

unread,
Jun 5, 2015, 12:56:28 PM6/5/15
to cloju...@googlegroups.com
I think it would make more sense to add a transducer arity to frequencies.  Distinct not so much, as there is already (into #{}) with a transducer.

Alex Miller

unread,
Jun 5, 2015, 2:44:12 PM6/5/15
to cloju...@googlegroups.com
I'd be happy to have a ticket for frequencies transducer. not for 1.7 at this point...

distinct already has a transducer arity :)  either into as you mention or possibly dedupe are probably better though.



--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.
To post to this group, send email to cloju...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojure-dev.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages