-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transduce / transformer Description #2457
Comments
Just to be clear, I'm not suggesting you need to explain transducers - there are lots of resources for understanding them online. However I think there is a lack of information about Ramda's implementation of transducers. I guess ideally there would be a layer on top of the docs for discussing the bigger picture (or bigger pictures).
I'm struggling to suggest how to improve the docs because I don't fully understand their use in the context of Ramda. All I can do is outline the questions I'm left with which I will do, though I fully appreciate this isn't a help forum, so that's probably not going to be very helpful. Rereading the description I quoted above, I find it very opaque. If the examples clearly illustrated the description, then that would make it easier to decode, but they don't. So I suppose the single most useful change would be to add some more examples illustrating the description, showing a custom function that can be used as a transformer perhaps to better illustrate its signature. |
I think this documentation was written by people deeply involved with adding transducers to Ramda, people who already had their head wrapped around transducers. There is a lot of room for improvement here. While I'm still looking for suggestions, I'll see if I can find a little time to try my hand at this. |
I alose have the problem to understand the transduce in ramda |
in the transduce description a trasformer is defined as an object comprising three methods (init, step, result), but I couldn't find any example throughout the documentation. In the useWith description a "transformer function" is referenced, which is obviously not a transformer, but no definition is provided. I would suggest:
|
Ok, the problem with the transformer definition is that its properties are not exactly init, step, result, but they have a "@@transducer/" prefix (thanks to #1658 (comment) ). const numbers = [1, 2, 3, 4];
const transducer = R.map(R.add(1));
R.transformer = function (init, result, step) {
return {
'@@transducer/init': init,
'@@transducer/step': step,
'@@transducer/result': result
};
};
const transformer = R.transformer(R.always(1), R.identity, R.add);
R.transduce(transducer, transformer, 0, numbers); //=> 14
const badtransformer = {init: R.always(1), step: R.add, result: R.identity};
R.transduce(transducer, badtransformer , 0, numbers); //=> t['@@transducer/step'] is not a function it would be nice if this can be put explicitly in the documentation. |
The docs for transduce say:
Although Ramda's docs are really excellent, this is hugely confusing for the following reasons:
map
,filter
etc).map
being used within a function calledtransducer
which is counter intuitive ifmap
is a transducer.Transducers are tricky to understand anyway, and even though I know your docs are minimal, I thought this one was worth looking at.
The text was updated successfully, but these errors were encountered: