@lou.codes/iterables
Version:
🔁 Iterable and AsyncIterable utils
23 lines (22 loc) • 582 B
TypeScript
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>>;