Skip to content

Function: skipWhile()

skipWhile<T>(predicate): Operator<T, T>

Defined in: operators/skipWhile.ts:17

Creates a stream operator that skips values from the source stream while a predicate returns true.

This operator is a powerful filtering tool for removing a contiguous prefix of a stream. It consumes values from the source and applies the predicate function to each one. As long as the predicate returns true, the values are ignored. As soon as the predicate returns false for the first time, this operator begins to emit that value and all subsequent values from the source, regardless of whether they satisfy the predicate.

Type Parameters

T

T = any

The type of the values in the source and output streams.

Parameters

predicate

(value) => CallbackReturnType<boolean>

The function to test each value. true means to continue skipping, and false means to stop skipping and begin emitting.

Returns

Operator<T, T>

An Operator instance that can be used in a stream's pipe method.

Examples

From skipWhile.spec.ts:4

typescript
const source$ = from([1, 2, 3, 4, 5]);
const result: number[] = [];
source$.pipe(skipWhile((val) => val < 3)).subscribe({
  next: (val) => result.push(val),
  complete: () => {
    expect(result).toEqual([3, 4, 5]);
    done();
  },
  error: done.fail,
});

Released under the MIT License.