ts-iterable-functions
    Preparing search index...

    Function _first

    • Returns the first element from the source iterable that satisfies an optional predicate.

      Type Parameters

      • T

        Element type produced by the source iterable.

      Parameters

      • src: Iterable<T>

        Source iterable evaluated sequentially until a match is found.

      • Optionalpred: IndexedPredicate<T>

        Optional predicate receiving the current value and index; defaults to accepting every value.

      Returns T

      The first element that matches the predicate.

      Error - Thrown when the iterable is empty or no element satisfies pred.

      const value = _first(["red", "green", "blue"]);
      console.log(value); // "red"

      or using the curried version:

      const value = pipeInto(
      [1, 2, 3, 4],
      first((n) => n > 2)
      );
      console.log(value); // 3