Skip to content

Instantly share code, notes, and snippets.

@souenzzo
Created May 31, 2019 19:39
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 souenzzo/0dab785fc21486fc273359740acc2f13 to your computer and use it in GitHub Desktop.
Save souenzzo/0dab785fc21486fc273359740acc2f13 to your computer and use it in GitHub Desktop.
(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