From the course: Learning RxJS

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Starting subscriptions with first, last, and skipWhile

Starting subscriptions with first, last, and skipWhile

From the course: Learning RxJS

Starting subscriptions with first, last, and skipWhile

- [Instructor] Building off of our weather app example, we sometimes only care about the first or last value that meets our criteria. For our weather app, maybe we want to know about the first sunny day we can go to the beaches or we may care about the last cold day of the winter. If that's the case, we can use the operator's first and last to only trigger our subscription function when the first or last values passed by our dataset meet our criteria. With our temperature values in this marble diagram, we can simplify it to be just the first like we see here. We also have the choice to only show the last value that meets our criteria. To take it another step further, we can also choose to start omitting days after the first 70 degree day using SkipWhile. Let's take a look at using these operators in code. In our code editor, I've already imported the observable from RxJS. Let's also import last and from. Last will…

Contents