Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 1.29 KB

reduce.md

File metadata and controls

38 lines (28 loc) · 1.29 KB
id lesson compare mainCompare focusOn video learnBackAbout learnAbout title layout class preview_image preview_image_alt revised
reduce
22
reduce
scan
reduce
scan
255356781
throttleTime
max
reduce versus scan operator in RxJS (with animations!)
default
post
reduce/content_preview.jpg
reduce vs scan
Monday, 26 Nov. 2018

❚ reduce takes the same three arguments as ❚ scan:

  • an input stream
  • an accumulator function (e.g. prepend a character to a string)
  • an initial value called seed (e.g. !)

Learn more about scan

Notes

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).

See also

{:.w300}
accumulator

{:.w300}
The JavaScript pipeline operator proposal

{:.w450.shadow-lg}
Launchpad for RxJS