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

Episode 19 - last vs first. Are they symmetrical? Monday, 22 Jan.

Today’s card is ❚ first. This is how it operates:

Read more about stream completion in Episode 9.

Take vs First

Question: Do ❚ take(1) and ❚ first() return the same stream of events?



Answer: Clearly, ❚ take(1) and ❚ first() return the same stream of events when the input stream emits at least one event. But the results may be different if the input stream emits no value before its completion (I’ll detail such edge cases in a future episode).

Last vs First

❚ last (seen in Episode 10) is the counterpart of ❚ first:

Question: Are ❚ last and ❚ first outputs identical when the input stream emits only one value?




Answer: Not when the input stream emits only one value and completes later or never completes. ❚ first and ❚ last are not strictly “symmetrical”. Remember that ❚ last has to wait for the ◉ complete notification (read more about stream completion).

Quick Exercises

Given a stream of numbers, return a stream that emits only the first even number and completes immediately. For example, given the stream 1 1 1 0 1 0 0 1, emit only the first 0.

And what about emitting the last even number?

Ep. 18 Ep. 20 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.