Created
July 1, 2020 09:51
-
-
Save helins/03317879b5722baa9e915ff7dde28e3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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