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. 9 Ep. 11 Newsletter Watch all Source on Github

Episode 10 - Last value? Monday, 20 Nov.

Today, we explore a card named ❚ last. As soon as the input stream emits its last value, the output stream emits it? Naaah! How could one be certain that no value comes after? Reactive programming can’t see the future.

We have to wait for a ◉ complete notification (read Episode 9 - Take 3 and complete to learn more about it). Only when the stream has completed, we know this value was the last one – and this completion may never happen!

Last Monday, we used the card ❚ take (watch it again below). The stream it outputs has a ◉ complete notification overlapped by the 3 value, as it completes immediately. I would like to emphasize that this notification is not intended to deliver the last value of the stream. It is a separate event, without a value (though it can happen immediately after an event value).

To illustrate all those principles, let’s see how ❚ last and ❚ take work with an input stream that completes a few seconds after the last value emitted:

This is how ❚ last operates with one input stream:

So, this card returns a new stream of at most one value.

Note: what happens if the stream completes without emitting a value depends on the reactive library you use.

Summary

See also

Episode 31 - takeLast vs take

Ep. 9 Ep. 11 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.