diff options
author | Stuart Sierra <mail@stuartsierra.com> | 2008-12-11 15:13:20 +0000 |
---|---|---|
committer | Stuart Sierra <mail@stuartsierra.com> | 2008-12-11 15:13:20 +0000 |
commit | 77e3f003e03c46d99204ca6d006143d22dbd7098 (patch) | |
tree | baacd36994a60407f540029860cfb52cc5d6e436 | |
parent | 60b48644f49063132a93145538feca1543abe4e8 (diff) |
seq_utils.clj: added "frequencies"
Adapted from various versions posted at
http://groups.google.com/group/clojure/browse_thread/thread/256cbf2a0ae6a27a
-rw-r--r-- | src/clojure/contrib/seq_utils.clj | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/clojure/contrib/seq_utils.clj b/src/clojure/contrib/seq_utils.clj index 4a8e7c57..c5e0036f 100644 --- a/src/clojure/contrib/seq_utils.clj +++ b/src/clojure/contrib/seq_utils.clj @@ -68,3 +68,11 @@ (when-not (identical? s ends) (lazy-cons (first s) (this (rest s)))))] (lazy-cons (tw s) (partition-by f ends))))) + +(defn frequencies + "Returns a map from distinct items in coll to the number of times + they appear." + [coll] + (reduce (fn [counts x] + (assoc counts x (inc (get counts x 0)))) + {} coll)) |