Skip to content

Commit

Permalink
Add group-by
Browse files Browse the repository at this point in the history
  • Loading branch information
madstap committed May 5, 2024
1 parent 52683d7 commit 1e25be2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/jank/clojure/core.jank
Original file line number Diff line number Diff line change
Expand Up @@ -2689,6 +2689,18 @@
(assoc counts x (inc (get counts x 0))))
{} coll))

(defn group-by
"Returns a map of the elements of coll keyed by the result of
f on each element. The value at each key will be a vector of the
corresponding elements, in the order they appeared in coll."
[f coll]
;; OPTIMIZE: transient
(reduce
(fn [ret x]
(let [k (f x)]
(assoc ret k (conj (get ret k []) x))))
{} coll))

(defn reductions
"Returns a lazy seq of the intermediate values of the reduction (as
per reduce) of coll by f, starting with init."
Expand Down Expand Up @@ -3297,7 +3309,6 @@
through each form for which the corresponding test expression
is true. Note that, unlike cond branching, cond->> threading does not short circuit
after the first true test expression."
{:added "1.5"}
[expr & clauses]
(assert (even? (count clauses)))
(let [g (gensym)
Expand Down

0 comments on commit 1e25be2

Please sign in to comment.