Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.26 KB

take.md

File metadata and controls

41 lines (31 loc) · 1.26 KB
id mainCompare seeAlso seeAlsoLink lesson video compare learnAbout learnBackAbout title layout class preview_image preview_image_alt
take
take
filter vs map
filter
9
242296640
take
filter
takeWhile
combineLatest
Take versus Filter operator and Stream completion
default
post
take/content_preview.jpg
Take 3 and complete

take

❚ take returns a new stream of at most amount values:

  • When the input stream emits its n-th value:
    • if n < amount, the event can pass
    • if n == amount, the event can pass and the stream immediately completes

Stream completion

What does "the stream completes" mean? As a reminder, a stream is a sequence of events over time. And you can subscribe to a stream, using a listener. Let's dive into the details now:

  • A stream can emit three kinds of events:
    • values
    • an × error: e
    • a ◉ complete notification
  • After an × error: e or a ◉ complete notification, nothing else is emitted by the stream.
  • A listener can receive those three kinds of events. So, it can consume the values, handle an error and act upon completion of the subscribed stream.

See also

{:.w300}
takeWhile