Skip to content

takeWhileInclusive

takeWhileInclusive<T>(iterable, predicate): IterableIterator<T>

Defined in: packages/core/src/iterable/take-while-inclusive.ts:19

Yields elements for as long as predicate holds, including the first one that fails it.

One of the two cases takeWhile gets wrong: it consumes the failing element and discards it, which loses a terminator a caller needs — a delimiter, a sentinel, the record that closed a run. Use beforeAndAfter when both sides are wanted.

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. The first element it rejects is yielded, and iteration stops after it.

IterableIterator<T>

An iterator over the prefix, terminator included.