dotfiles/init/FiraCode/clojure/fira_code/coll.clj

15 lines
314 B
Clojure
Raw Normal View History

2020-05-07 09:30:45 +02:00
(ns fira-code.coll)
(defn index-of [pred xs]
(let [res (reduce (fn [i x] (if (pred x) (reduced i) (inc i))) 0 xs)]
(assert (< res (count xs)) "Nothing found")
res))
(defn group-by-to [key-fn value-fn xs]
(reduce-kv
(fn [m k vs]
(assoc m k (value-fn vs)))
{}
(group-by key-fn xs)))