head
head() function
Returns the first element of Iterable/AsyncIterable. (head)
Signature:declare function head<T extends Iterable<unknown> | AsyncIterable<unknown>>(iterable: T): HeadReturnType<T>;
Example
head([1, 2, 3, 4, 5]); // 1
// with pipe
pipe(
[1, 2, 3, 4, 5],
head,
); // 1
await pipe(
Promise.resolve([1, 2, 3, 4, 5]),
head,
); // 1
// with toAsync
await pipe(
[Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)],
toAsync,
head,
); // 1