source: node_modules/es-toolkit/dist/array/head.d.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/**
2 * Returns the first element of an array.
3 *
4 * This function takes an array and returns the first element of the array.
5 * If the array is empty, the function returns `undefined`.
6 *
7 * @template T - The type of elements in the array.
8 * @param {[T, ...T[]]} arr - A non-empty array from which to get the first element.
9 * @returns {T} The first element of the array.
10 *
11 * @example
12 * const arr = [1, 2, 3];
13 * const firstElement = head(arr);
14 * // firstElement will be 1
15 */
16declare function head<T>(arr: readonly [T, ...T[]]): T;
17/**
18 * Returns the first element of an array or `undefined` if the array is empty.
19 *
20 * This function takes an array and returns the first element of the array.
21 * If the array is empty, the function returns `undefined`.
22 *
23 * @template T - The type of elements in the array.
24 * @param {T[]} arr - The array from which to get the first element.
25 * @returns {T | undefined} The first element of the array, or `undefined` if the array is empty.
26 *
27 * @example
28 * const emptyArr: number[] = [];
29 * const noElement = head(emptyArr);
30 * // noElement will be undefined
31 */
32declare function head<T>(arr: readonly T[]): T | undefined;
33
34export { head };
Note: See TracBrowser for help on using the repository browser.