Created
January 14, 2020 14:01
-
-
Save craftybones/2163fed07e2ce5b755ce7bc2b65d1fe9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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-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