Skip to content

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.

T

Iterable<T>

The input iterable.

Predicate<[T, number]>

Receives each element and its zero-based index. Yielding stops the first time it returns false.

IterableIterator<T>

An iterator over the leading elements that satisfy predicate.