Essentials

Skipping

Reducing

Concatenating

  • startWith (soon)
  • endWith (soon)
  • concat (soon)

Combining

Illustration
How it works

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

takeLast

accepts 1 input stream, an amount

  • When the input stream completes, the output stream:
    • emits each of the last amount values emitted by the input stream (they are emitted as separate event values)
    • and immediately completes
  • If the input stream never completes, the output stream never emits

returns a new stream of at most amount values

Published on Monday, 16 Apr. 2018
Revised on Monday, 8 Oct. 2018

Learn more about stream completion.

Use a ▬ number on these cards, such as 3, to set a maximum amount of events to emit. ❚ take and ❚ takeLast share identical behavior:

  • they both return a new stream of at most amount values.
  • if the input stream source emits fewer than amount values then all of its values are emitted on the output stream.

The stream returned by ❚ take emits the values at the same time as their counterpart on the input stream. This is not the case for ❚ takeLast. Remember: a stream is a sequence of events over time. And we can’t see the future! takeLast must wait for the ◉ complete notification. Only then, we know what are the last values.

See also


Pipeable operators - Build your own with RxJS!

Cédric Soulas

Follow Contact Hire me

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

Receive my latest news, tips and animations:

Learn Reactive Programming and stay up-to-date:

News

@CedricSoulas