Skip to content

Instantly share code, notes, and snippets.

@ataggart
Last active August 29, 2015 14:02
Show Gist options
  • Save ataggart/85b4dbb5b097bd8331f1 to your computer and use it in GitHub Desktop.
Save ataggart/85b4dbb5b097bd8331f1 to your computer and use it in GitHub Desktop.
take-until
(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