id | lesson | compare | mainCompare | focusOn | video | learnBackAbout | learnAbout | title | layout | class | preview_image | preview_image_alt | revised | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
reduce |
22 |
|
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 astring
) - an initial value called seed (e.g.
!
)
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)
.