take
accepts
1
input stream,
an amount
amount
, the value is emittedamount
, the value is emitted and the stream immediately completesreturns
a new stream of at most amount
values
takeWhile
accepts
1
input stream,
a predicate
function
predicate
:
predicate
returns ✔ true
, the value is emittedreturns a new stream of filtered values
In the animation above, can you spot the difference between the outputs? Can you explain why?
Answer: the ◉ complete
notification happens at a different moment:
❚ take
returns a stream that emits at most amount values and can complete as soon as this amount is reached.❚ takeWhile
has to wait for the predicate to return ✘ false
in order to complete.Freelance Developer Advocate. Motion graphics with code. JavaScript and Elm. cedricsoulas.com
Receive my latest news, product updates and programming visualizations. You can unsubscribe at any time.