ts-iterable-functions
    Preparing search index...

    Function _singleOrDefault

    • Returns the unique element that satisfies the optional predicate, or undefined when no match is found.

      Type Parameters

      • T

        Element type produced by the source iterable.

      Parameters

      • src: Iterable<T>

        Source iterable to evaluate.

      • pred: IndexedPredicate<T> = ...

        Predicate receiving each element and its index; the matching element must be unique when provided.

      Returns T | undefined

      The sole element accepted by pred, or undefined when no element matches.

      Error Thrown when more than one element satisfies pred.

      Error Rethrows any error thrown by pred.

      const value = _singleOrDefault([1, 2, 3], (item) => item > 3);
      console.log(value); // undefined

      or using the curried version:

      const value = pipeInto(
      [1, 2, 3],
      singleOrDefault((item) => item > 3)
      );
      console.log(value); // undefined