UNPKG

@lou.codes/iterables

Version:
23 lines (22 loc) 582 B
import type { Head, IsomorphicIterableItem, Maybe, ReadOnlyArray, ReadOnlyIterable, } from "@lou.codes/types"; /** * Get first element of an iterable (`undefined` if it is empty). * * @category Reducers * @example * ```typescript * head([1, 2, 3]); // 1 * ``` * @param iterable Iterable to get the first element from. * @returns First element of the iterable (`undefined` if empty). */ export declare const head: <Iterable extends ReadOnlyIterable>( iterable: Iterable, ) => Iterable extends ReadOnlyArray ? Head<Iterable> : Maybe<IsomorphicIterableItem<Iterable>>;