UNPKG

@lou.codes/iterables

Version:
14 lines (13 loc) 401 B
import { getIterator } from "./getIterator.js"; /** * 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 const head = iterable => getIterator(iterable).next().value;