Skip to content

Instantly share code, notes, and snippets.

@craftybones
Created January 14, 2020 14:01
Show Gist options
  • Save craftybones/2163fed07e2ce5b755ce7bc2b65d1fe9 to your computer and use it in GitHub Desktop.
Save craftybones/2163fed07e2ce5b755ce7bc2b65d1fe9 to your computer and use it in GitHub Desktop.
(defn take-while-adjacent [pred]
(fn [rf]
(let [prev (volatile! ::none)]
(fn ([] (rf))
([result] (rf result))
([result input]
(let [pv @prev]
(if (or (identical? pv ::none) (pred @prev input))
(do
(vreset! prev input)
(rf result input))
(reduced result))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment