ts-iterable-functions
    Preparing search index...

    Function _single

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

      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.

      Returns T

      The sole element accepted by pred, or the only element in the sequence when pred is omitted.

      Error Thrown when the sequence contains no matching elements or more than one match.

      Error Rethrows any error thrown by pred.

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

      or using the curried version:

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