I'm trying to understand Ramda's transducers. Here's a slightly modified example from the docs:
const numbers = [1, 2, 3, 4];
const isOdd = (x) => x % 2 === 1;
const firstFiveOddTransducer = R.compose(R.filter(isOdd), R.take(5));
R.transduce(firstFiveOddTransducer, R.flip(R.append), [], R.range(0, 100)); //=> [ 1, 3, 5, 7, 9 ]
But what if I want to sum the elements of the resulting array? The following (just adding R.sum
into R.compose
) doesn't work:
const firstFiveOddTransducer = R.compose(R.filter(isOdd), R.take(5), R.sum);