Function takeWhile

  • Takes elements from the source while the predicate returns true.

    Type Parameters

    • T

      Type of items in the source.

    Parameters

    • predicate: PredicateFunction<T>

      Predicate function to determine if an element should be taken.

    Returns OperationFunction<T, T>

    Operation that takes elements from the source while the predicate returns true.

    const result = takeWhile<number>((x) => x < 3)([1, 2, 3, 4]);
    console.log([...result]); // [1, 2]