Skip to content

Instantly share code, notes, and snippets.

@ecounysis
Created June 3, 2016 23:47
Show Gist options
  • Save ecounysis/59478840c99d317f2e857ebfde935ee0 to your computer and use it in GitHub Desktop.
Save ecounysis/59478840c99d317f2e857ebfde935ee0 to your computer and use it in GitHub Desktop.
(defn summarize
"Summarizes a data set. Groups data by result of groupingf applied to each
member of coll. Applies summarizingf to each group."
[groupingf summarizingf coll]
(let [grouped (group-by groupingf coll)]
(map #(list (first %) (summarizingf (second %))) grouped)))
(defn summarize-count
[groupingf coll]
(summarize groupingf count coll))
; juxt is the non-str version of catf
(defn catf
[sep & fs]
(fn [x]
(clojure.string/join sep ((apply juxt fs) x))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment