Cédric Soulas
Motion graphics about programming


Episode 22 - reduce vs scan Monday, 12 Feb.

In Episode 21, you learned about ❚ scan and the accumulator function.

❚ reduce takes the same three arguments as ❚ scan:

So, what is the difference between ❚ reduce and ❚ scan?

reduce vs scan

I’ve highlighted the differences:



As you can see, while ❚ scan returns a new stream of progressively accumulated values, ❚ reduce returns a new stream of, at most, one value. At most? If the input stream never completes, ❚ reduce will never emit any value on the output stream.

Ultimately, ❚ reduce is equivalent to ❚ scan chained with ❚ last (read Episode 10 - Last value).

Cards to learn Reactive Programming

Focus on one new concept – every Monday

Occasional updates, plus:
Cédric Soulas
Motion graphics about programming