take

accepts 1 input stream, an amount

  • ❯When the input stream emits its n-th value:
    • if n < amount, the value is emitted
    • if n == amount, the value is emitted and the stream immediately completes

returns a new stream of at most amount values

filter

accepts 1 input stream, a predicate function

  • ❯When the input stream emits a value, it is given to the predicate:
    • If the predicate returns âś” true, the value is emitted
    • Otherwise, the value is ignored

returns a new stream of filtered values

Published on Monday, 13 Nov. 2017
Revised on Monday, 8 Oct. 2018

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


takeWhile

Cédric Soulas Follow Hire me

Freelance Developer Advocate. Motion graphics with code. JavaScript and Elm. cedricsoulas.com

Subscribe to reactive.how newsletter

Join the Newsletter

Learn Reactive Programming and stay up-to-date:

Receive my latest news, product updates and programming visualizations. You can unsubscribe at any time.

Highlights

@CedricSoulas

Making an illustrated book!

The Illustrated Book of RxJS

Learn more →