Back to Es Toolkit

dropWhile (Functional Programming)

docs/fp/reference/dropWhile.md

1.49.0990 B
Original Source

dropWhile (Functional Programming)

Creates a function that drops leading values while a predicate passes. Use it with pipe.

typescript
const result = pipe(array, dropWhile(predicate));

::: info

Prefer the original es-toolkit dropWhile in ordinary code. Use this fp variant when composing transformations with pipe.

:::

Usage

dropWhile walks the piped array from the beginning and removes values while predicate returns true. It is lazy-capable inside pipe.

typescript
import { dropWhile, pipe } from 'es-toolkit/fp';

pipe(
  [1, 2, 3, 1],
  dropWhile(value => value < 3)
); // => [3, 1]

Parameters

  • predicate ((item: T, index: number) => boolean): The function that decides whether a leading value should be dropped.

Returns

((array: readonly T[]) => T[]): A function that maps a readonly T[] to the values left after dropping from the beginning.