transduce / transformer Description
Author: UndistractionCreated Feb 1, 2018Updated Aug 14, 2023
Labelsdocumentation
The docs for transduce say:
A transformer is an an object that provides a 2-arity reducing iterator function, step, 0-arity initial value function, init, and 1-arity result extraction function, result. The step function is used as the iterator function in reduce. The result function is used to convert the final accumulator into the return type and in most cases is R.identity. The init function can be used to provide an initial accumulator, but is ignored by transduce.
Although Ramda's docs are really excellent, this is hugely confusing for the following reasons:
- It doesn't explain that there are multiple functions in the lib that can be used as transducers (
map,filteretc). - It doesn't explain how these functions can be used as transducers. It shows
mapbeing used within a function calledtransducerwhich is counter intuitive ifmapis a transducer. - It doesn't clearly explain what a transformer's signature should be and doesn't give an example of a custom transformer. A simple example of a vanilla transformer function would be really helpful here.
Transducers are tricky to understand anyway, and even though I know your docs are minimal, I thought this one was worth looking at.
Source: ramda/ramda