Skip to content

Instantly share code, notes, and snippets.

@garlic0x1
Last active July 25, 2023 09:06
Show Gist options
  • Save garlic0x1/0b6db302aa1b079244176c1cfc79fef0 to your computer and use it in GitHub Desktop.
Save garlic0x1/0b6db302aa1b079244176c1cfc79fef0 to your computer and use it in GitHub Desktop.
[Clojure] Tally unique items in sequence
(defn tally
"tally unique things in a sequence"
[seq]
(reduce (fn [ag i] (update ag i (fnil inc 0))) {} seq))
;; (tally [:a :a :a :b :b :c])
;; => {:a 3, :b 2, :c 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment