Skip to content

Instantly share code, notes, and snippets.

@Quantisan
Created October 25, 2011 17:09
Show Gist options
  • Save Quantisan/1313522 to your computer and use it in GitHub Desktop.
Save Quantisan/1313522 to your computer and use it in GitHub Desktop.
(defn match-count
" Given key, k, returns number of occurrences of k in collection, coll.
"
[k coll]
(let [match? (fn [i x]
(if (= k x) ;; closure on k
(inc i)
i))]
(reduce match? 0 coll)))
(defn calc-counts
" Returns a list of counts for the occurrences of each key of keys, ks,
within the collection, coll.
"
[ks coll]
(pmap #(match-count % coll) ks))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment