Created
December 29, 2014 17:58
-
-
Save favila/ecdd031e22426b93a78f to your computer and use it in GitHub Desktop.
as-transducer: convenience function to make a full transducer from a reducing-step function which accepts three arguments: the transforming function (xf), the reduced value, and the step value from the reduction.
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 as-transducer [f] | |
"Convert function f into a transducer function. | |
This is merely a more convenient way to write an efficient reducing-step | |
function without the transducer signature. | |
The function should have the signature `(f transformer opaque-collection value)` | |
and return either `opaque-collection` or the return value of | |
`(transformer opaque-collection value)` to return new `opaque-collection` | |
things with `value` \"added\" to it. It can also box its return value with | |
`reduced` to terminate reduction early." | |
(fn [xf] | |
(fn | |
([] (xf)) | |
([r] (xf r)) | |
([r v] (f xf r v))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment