yeah to me this just hollers for the kind of "pour it through the functions" approach we see in functional languages or even with Ramda.pipe in JS. Ezpz.
(1..5)
.into_iter()
.filter(|i| i % 3 == 1)
.map(|i| i * i)
.sum();
I don't know if we really need a new syntax for map reduce. import { range } from 'ramda';
range(1, 6)
.filter(i => i % 3 === 1)
.map(i => i * i)
.reduce((a, b) => a + b, 0);
Or, if you're using the pipeline operator (experimental, stage 1, nobody can quite decide on exactly the syntax but this gives the rough idea): import { range, sum } from 'ramda';
range(1, 6)
|> x => x.filter(i => i % 3 === 1)
|> x => x.map(i => i * i)
|> sum pipe(
range,
filter(pipe(
modulo(__, 3), // x => x % 3
equals(1) // y => y === 1
)),
map(flip(Math.pow)(2)),
sum
)(1,6)