Skip to content

Latest commit

 

History

History
36 lines (28 loc) · 1.15 KB

scan.md

File metadata and controls

36 lines (28 loc) · 1.15 KB
id compareWith lesson compare video learnBackAbout learnAbout title layout class preview_image preview_image_alt revised
scan
reduce
21
scan
254283000
filter
merge
The RxJS scan operator and the accumulator function
default
post
scan/content_preview.jpg
Scanning a stream
Monday, 26 Nov. 2018

Scan arguments

❚ scan takes three arguments:

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

The accumulator function combines two values:

  • an accumulated value called accumulation
  • and a value

As a result, the accumulator returns a new accumulation.

Notes

  • As you can see, the output stream does not start with the seed. This is how it works, for example, in RxJS.
  • In some other reactive stream libraries (like xstream and Most.js) the output stream starts with the seed.
  • To start with the seed in RxJS and such, you can chain ❚ startWith(seed) and ❚ scan(f, seed).