Skip to content

Instantly share code, notes, and snippets.

@mpenet
Last active September 13, 2018 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpenet/35451344629372b34bdb2280aade387e to your computer and use it in GitHub Desktop.
Save mpenet/35451344629372b34bdb2280aade387e to your computer and use it in GitHub Desktop.
(defn until
[p]
(fn [rf]
(let [p? (volatile! false)]
(fn
([x] (rf x))
([x y]
(if @p?
x
(do
(when (p y)
(vreset! p? true))
(rf x y))))))))
(into []
(until #(re-find #"\." %))
["ciao" "mi" "piace" "clojure." "Ed" "altro"])
(sequence (until #(re-find #"\." %))
["ciao" "mi" "piace" "clojure." "Ed" "altro"])
(transduce (until #(re-find #"\." %))
conj
["ciao" "mi" "piace" "clojure." "Ed" "altro"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment