Prelude API
    Preparing search index...

    Function single

    • Returns the single element in an iterable. Throws an error if the iterable contains zero or more than one element.

      Type Parameters

      • T

        Element type

      Parameters

      • values: Iterable<T>

        The input iterable

      Returns T

      The single element in the iterable

      If there are no elements in the iterable

      If there is more than one element in the iterable

      maybeSingle - Non-throwing variant that returns undefined for 0 or >1 elements

      G.pipe(
      G.of([42]),
      G.single
      ) // 42

      // Throws "Expected single element, got more."
      G.pipe(
      G.range(1, 2),
      G.single
      )