Function optional

  • Creates an Optional from a given iterable or a function that produces an iterator. If the iterable (or iterator) is empty, the optional resolves to empty. Otherwise, the optional resolves to the first item yielded by the iterator, and all subsequent elements are discarded.

    Type Parameters

    • T

      The type of elements in the optional.

    Parameters

    • input: Iterable<T, any, any> | () => Iterator<T, any, any>

      The source to create the optional from. The input is interpreted in the same way as described in the stream function.

    Returns Optional<T>

    An Optional containing the first item of the iterable, or empty if the iterable is empty.