DieselDepot-APP/node_modules/es-toolkit/dist/fp/array/head.d.mts
SJCoetz def597c157 chore: add generated build artifacts and node module type files
add all Next.js build outputs and third-party dependency type declaration files
2026-07-20 01:18:42 +02:00

35 lines
No EOL
1.1 KiB
TypeScript

//#region src/fp/array/head.d.ts
/**
* Creates a function that returns the first element of a non-empty array.
*
* This overload preserves the non-empty tuple guarantee: the returned function
* always returns T when the piped array has at least one element.
*
* @template T - The type of elements in the array.
* @returns A function that maps a non-empty readonly array to its first element.
*
* @example
* import { head, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3] as const, head());
* // => 1
*/
declare function head<T>(): (array: readonly [T, ...T[]]) => T;
/**
* Creates a function that returns the first element of an array, or undefined.
*
* Empty arrays return undefined, matching the main {@link head} behavior. Use
* the returned function with {@link pipe}.
*
* @template T - The type of elements in the array.
* @returns A function that maps a readonly array to its first element, or undefined.
*
* @example
* import { head, pipe } from 'es-toolkit/fp';
*
* pipe([] as number[], head());
* // => undefined
*/
declare function head<T>(): (array: readonly T[]) => T | undefined;
//#endregion
export { head };