takeWhile
signature: takeWhile(predicate: function(value, index): boolean, inclusive?: boolean): Observable
takeWhile(predicate: function(value, index): boolean, inclusive?: boolean): Observable
Emit values until provided expression is false.
💡 When the optional inclusive
parameter is set to true
it will also emit the first item that didn't pass the predicate.
Examples
Example 1: Take values under limit
( StackBlitz | jsBin | jsFiddle )
Example 2: (v6.4+) takeWhile with inclusive flag
( StackBlitz )
Example 3: Difference between takeWhile
and filter
( StackBlitz | jsBin | jsFiddle )
Related Recipes
Additional Resources
takeWhile 📰 - Official docs
takeWhile - In Depth Dev Reference
Completing a stream with takeWhile 🎥 💵 - John Linquist
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/takeWhile.ts
Last updated