Created
May 31, 2019 19:39
-
-
Save souenzzo/0dab785fc21486fc273359740acc2f13 to your computer and use it in GitHub Desktop.
This file contains 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
(let [xparir-transform (fn [{:keys [initial-value transform-fn]}] | |
(fn [rf] | |
(let [old (volatile! initial-value)] | |
(fn | |
([] (rf)) | |
([result] (rf result)) | |
([result input] | |
(let [new (transform-fn input @old)] | |
(vreset! old input) | |
(rf result new)))))))] | |
(sequence (xparir-transform {:initial-value [] | |
:transform-fn (fn [current prev] | |
(let [eq? (= (last current) | |
(last prev))] | |
(conj current (not eq?))))}) | |
[[1] [2] [2] [2] [3] [4]])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment