ts-iterable-functions
    Preparing search index...

    Function _firstOrDefault

    • Returns the first element in the source iterable that satisfies the predicate or undefined if none do.

      Type Parameters

      • T

        Element type produced by the source iterable.

      Parameters

      • src: Iterable<T>

        Source iterable examined until a matching element is found.

      • pred: IndexedPredicate<T> = ...

        Predicate receiving the current value and index; defaults to a function that accepts every value.

      Returns T | undefined

      The first matching element, or undefined when the predicate never returns true.

      const value = _firstOrDefault([10, 20, 30]);
      console.log(value); // 10

      or using the curried version:

      const value = pipeInto(
      [1, 2, 3],
      firstOrDefault((n, i) => n > 5 || i > 5)
      );
      console.log(value); // undefined