takeWhile
takeWhile<
T>(iterable,predicate):IterableIterator<T>
Defined in: packages/core/src/iterable/take-while.ts:18
Yields elements from the start for as long as predicate holds, stopping at
the first one it rejects.
The rejecting element is consumed but not yielded, and nothing after it is
pulled — use takeWhileInclusive to keep it, or beforeAndAfter to keep
both sides.
Time complexity: O(1) per element, over the prefix only.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The input iterable.
predicate
Section titled “predicate”Predicate<[T, number]>
Receives each element and its zero-based index. Yielding
stops the first time it returns false.
Returns
Section titled “Returns”IterableIterator<T>
An iterator over the leading elements that satisfy predicate.