Skip to content

Instantly share code, notes, and snippets.

@alwx
Created January 30, 2016 13:33
Show Gist options
  • Save alwx/72236565ecdd4d818ca6 to your computer and use it in GitHub Desktop.
Save alwx/72236565ecdd4d818ca6 to your computer and use it in GitHub Desktop.
How transducers work (from https://www.youtube.com/watch?v=6mTbuzafcII)
(defn filtering [pred]
(fn [step]
(fn [r x] (if (pred x) (step r x) r))))
(defn my-filter
([pred coll]
"Returns the result immediately"
(reduce ((filtering pred) conj)
[] coll))
([pred]
"Return the step function to use it later"
((filtering pred) conj)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment