Can anyone explain why when I run ...
const logAndId = (n) => (x) => { console.log(n); return x }
const xform = R.pipe(R.map(logAndId(1)), R.map(logAndId(2)), R.map(logAndId(3)))
R.transduce(xform, R.flip(R.append), [], [5])
... I get 3, 2 & 1 in the logs?
If I change to compose I get 1, 2, & 3.
this might shed some light on the subject: http://isaaccambron.com/blog/2014/12/13/transducer-composition.html
So why does composing transducers mean they get evaluated “backwards” or “inside out”? Well, on reflection, it makes a lot of sense. What transducers really do is transform reducing functions, not actual values; they take one reducing function and return another one that works by transforming its values and passing the results to that passed-in reducing function. When you compose them, you’re using the function returned by the “inner” transducer as the reduction function for the “outer” transducer. So if I have (comp (map double) (map inc)), I’m saying that (map inc) provides a reducing function that takes a value, increments it, and feeds into the reducing function it gets passed. I’m then passing that reducing function into the doubling tansducer, which returns another reducing function that doubles the values and then feeds the answer into the map-incrementing reducer the doubler took as an argument. So double then inc.
Most helpful comment
this might shed some light on the subject: http://isaaccambron.com/blog/2014/12/13/transducer-composition.html