id | lesson | compare | mainCompare | image | learnAbout | learnBackAbout | title | layout | class | preview_image | preview_image_alt | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
takeLast |
31 |
|
take |
takeLast/takeLast-take.png |
delay |
skipWhile |
Reactive Programming - take vs takeLast |
default |
post |
takeLast/content_preview.jpg |
The "takeLast" operator |
Learn more about stream completion.
Use a ▬ number
on these cards, such as 3
, to set a maximum amount of events to emit. ❚ take
and ❚ takeLast
share identical behavior:
- they both return a new stream of at most amount values.
- if the input stream source emits fewer than amount values then all of its values are emitted on the output stream.
The stream returned by ❚ take
emits the values at the same time as their counterpart on the input stream. This is not the case for ❚ takeLast
. Remember: a stream is a sequence of events over time. And we can't see the future! takeLast must wait for the ◉ complete
notification. Only then, we know what are the last values.