@lou.codes/iterables
Version:
🔁 Iterable and AsyncIterable utils
24 lines (23 loc) • 627 B
TypeScript
import type {
Head,
IsomorphicIterable,
IsomorphicIterableItem,
Maybe,
ReadOnlyArray,
} from "@lou.codes/types";
/**
* Get first element of an iterable or asynchronous iterable (`undefined` if
* it is empty).
*
* @category Asynchronous 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 IsomorphicIterable>(
iterable: Iterable,
) => Iterable extends ReadOnlyArray ? Head<Iterable>
: Maybe<IsomorphicIterableItem<Iterable>>;