Welcome! Please see the About page for a little more info on how this works.
Discussion: https://groups.google.com/d/topic/clojure-dev/NaAuBz6SpkY/discussion
It comes up when I would otherwise use (take-while pred coll), but I need to include the first item for which (pred item) is false.
(take-while pos? [1 2 0 3]) => (1 2) (take-until zero? [1 2 0 3]) => (1 2 0)
Patch: clj-1451.patch
Comment made by: gshayban
I feel like this is superceded by CLJ-1906
And this is definitely superseded by halt-when
halt-when
Comment made by: alexmiller
It's not lazy but this is one way to write take-until with halt-when:
(defn take-until [p s] (transduce (halt-when p (fn [r h] (conj r h))) conj [] s))
Comment made by: steveminer@gmail.com
I wanted to suggest: (sequence (halt-when p conj) s) but sequence doesn't support stopping short on a reduced value so that won't work.
(sequence (halt-when p conj) s)
Yeah, halt-when is a little tricky to use in transducible contexts other than transduce.