Last active
August 29, 2015 14:02
-
-
Save ataggart/85b4dbb5b097bd8331f1 to your computer and use it in GitHub Desktop.
take-until
This file contains 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 take-until | |
"Returns a lazy sequence of successive items from coll until | |
(pred item) returns true, including that item. pred must be | |
free of side-effects. | |
E.g., (take-until zero? [1 2 0 3]) => (1 2 0)" | |
[pred coll] | |
(lazy-seq | |
(when-let [s (seq coll)] | |
(if (pred (first s)) | |
(cons (first s) nil) | |
(cons (first s) (take-until pred (rest s))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment