Cédric Soulas
I make motion graphics with RxJS. I code apps with JavaScript and Elm. I will be available for freelance work from mid-April 2018. Get in touch!

Ep. 21 Ep. 23 Newsletter Watch all Source on Github

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:

Reduce

Scan

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 ❚ takeLast(1).

Ep. 21 Ep. 23 Newsletter Watch all Source on Github

reactive.how list of animated cards

Learn Reactive Programming

Focus on one new concept – every Monday

Occasional updates, plus:

Cédric Soulas
I make motion graphics with RxJS. I code apps with JavaScript and Elm. I will be available for freelance work from mid-April 2018.