Prelude API
    Preparing search index...

    Function maybeSingle

    • Returns the first element from an iterable if it's the only element, undefined if there are no elements, or throws an error if there are multiple elements.

      Type Parameters

      • T

        Type of values in the iterable

      Parameters

      • values: Iterable<T>

        The input iterable

      Returns T | undefined

      The single element if it exists, or undefined if the iterable is empty

      Error if there are more than one elements

      single for a version that throws when there are no elements

      G.pipe(
      [42],
      G.maybeSingle
      ) // 42

      G.pipe(
      [],
      G.maybeSingle
      ) // undefined

      // This would throw an Error:
      // G.pipe([1, 2, 3], G.maybeSingle)