Skip to content

Instantly share code, notes, and snippets.

@helins
Created July 1, 2020 09:51
Show Gist options
  • Save helins/03317879b5722baa9e915ff7dde28e3a to your computer and use it in GitHub Desktop.
Save helins/03317879b5722baa9e915ff7dde28e3a to your computer and use it in GitHub Desktop.
(defn split-with
"Semi lazy alternative to `split-with`"
[pred coll]
(let [acc (transient [])]
(loop [[v
:as vs] coll]
(if (seq vs)
(if (pred v)
[(persistent! acc)
vs]
(do
(conj! acc
v)
(recur (rest vs))))
[(persistent! acc)
nil]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment