1
0
Fork 0
mirror of synced 2024-06-03 19:25:04 +12:00
FiraCode/clojure/fira_code/coll.clj
2020-03-24 00:37:50 +01:00

15 lines
314 B
Clojure

(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)))