3 ms·
So I checked the definition of a transducer,but i'm not smart enough to get it. What the difference between that library and say lodash where I can bind and com
by aikah 12y ago
So I checked the definition of a transducer,but i'm not smart enough to get it. What the difference between that library and say lodash where I can bind and compose functions? because it seems like the same stuff
var f=_.compose( _.partialRight(_.filter,isEven),_.partialRight(_.map,inc)) ;
or something.
- icholy 12y agoI think it only iterates over the collection once.
- rymohr 12y agoThat and they're collection agnostic. I highly recommend watching Rich Hickey's talk for more background: https://www.youtube.com/watch?v=6mTbuzafcII https://www.youtube.com/watch?v=6mTbuzafcII
- msoad 12y agoThen what happens to operations that access the collection? like third argument in JavaScript's native forEach?
- aeflash 12y agoIt's not supported. But if you're doing things right, you shouldn't need it.
- acjohnson55 12y agoThat's what a zipper [1] is good for. It gives you access to the rest of a collection relative to the current position. [1] http://en.wikipedia.org/wiki/Zipper_%28data_structure%29 http://en.wikipedia.org/wiki/Zipper_%28data_structure%29
- deleted 12y ago[deleted]
- kbeaty 12y agoTransducers allow the abstraction of algorithmic transformations independent from the input and output, and even the process of iteration. Whereas lodash operates on arrays and objects calculating intermediate results, transducers simply define the transformation in terms of functions similar to what you pass reduce: start with a memo, execute a function with a memo and an item, return the possibly transformed memo for the next iteration. Once you abstract the transformation away from the data, you can apply the same transformations to different processes that start with an initial value and step through a result. One benefit is that you can compute the result in one pass (without intermediate results). Another is you can use the same transformation in different contexts (lazy lists, indefinite sequence generation, CSP, event streams, etc.). The source could be anything that produces a sequences of values: streams, iterators, callbacks, immutable-js, etc. You simply have to define (external to the transducer) how you append each item to the supplied result. The "step function" that knows how to append results to values is passed to the transducer, and the transducer executes the step function when reducing over results. It's interesting you mention lodash in the context of transducers, as I have been developing my own take on transducers closely following the underscore API [1]. [1]: https://github.com/kevinbeaty/underscore-transducer https://github.com/kevinbeaty/underscore-transducer
- kbeaty 12y agoTransducers allow the abstraction of algorithmic transformations independent from the input and output, and even the process of iteration. Whereas lodash operates on arrays and objects calculating intermediate results, transducers simply define the transformation in terms of functions similar to what you pass reduce: start with a memo, execute a function with a memo and an item, return the possibly transformed memo for the next iteration. Once you abstract the transformation away from the data, you can apply the same transformations to different processes that start with an initial value and step through a result. One benefit is that you can compute the result in one pass (without intermediate results). Another is you can use the same transformation in different contexts (lazy lists, indefinite sequence generation, CSP, event streams, etc.). The source could be anything that produces a sequences of values: streams, iterators, callbacks, immutable-js, etc. You simply have to define (external to the transducer) how you append each item to the supplied result. The "step function" that knows how to append results to values is passed to the transducer, and the transducer executes the step function when reducing over results. It's interesting you mention lodash in the context of transducers, as I have been developing my own take on transducers closely following the underscore API [1]. [1]: https://github.com/kevinbeaty/underscore-transducer https://github.com/kevinbeaty/underscore-transducer