Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(defn split-coll [elem coll]
(loop [coll coll
parts []
part []]
(if-let [e (first coll)]
(if (= e elem)
(recur (rest coll) (conj parts part) [])
(recur (rest coll) parts (conj part e)))
(if (seq part)
(conj parts part)
parts))))
(defn split-coll [elem coll]
(loop [coll coll
parts (transient [])
part (transient [])]
(if-let [e (first coll)]
(if (= e elem)
(recur (rest coll) (conj! parts (persistent! part)) (transient []))
(recur (rest coll) parts (conj! part e)))
(let [part (persistent! part)]
(persistent!
(if (seq part)
(conj! parts part)
parts))))))
(time (dotimes [n 1000]
(split-coll :x (apply concat (repeat 100 [:a :b :c :x :x :d :x :e])))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment