Use seq/next idiom in enumerate instead of empty?/rest

Replace (empty? items) + (rest items) with (seq items) + (next items)
in enumerate. The seq/next pattern is idiomatic Clojure and avoids
the overhead of empty? which internally calls seq and then negates.
This commit is contained in:
Andrey Antukh 2026-04-14 20:06:13 +00:00 committed by Belén Albeza
parent 92dd5d9954
commit 1cc860807e

View File

@ -252,13 +252,13 @@
([items] (enumerate items 0)) ([items] (enumerate items 0))
([items start] ([items start]
(loop [idx start (loop [idx start
items items items (seq items)
res (transient [])] res (transient [])]
(if (empty? items) (if items
(persistent! res)
(recur (inc idx) (recur (inc idx)
(rest items) (next items)
(conj! res [idx (first items)])))))) (conj! res [idx (first items)]))
(persistent! res)))))
(defn group-by (defn group-by
([kf coll] (group-by kf identity [] coll)) ([kf coll] (group-by kf identity [] coll))