Skip to content

Commit

Permalink
feat(first): replace "head" with "first"
Browse files Browse the repository at this point in the history
The new name is much clearer. The old name will continue to work but is deprecated.

(cherry picked from commit 51ffc0f)
  • Loading branch information
djcsdy committed Dec 5, 2023
1 parent 7d4d287 commit 2a723e9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,20 @@ export function coerce<T>(array: ArrayLike<T>): readonly T[] {
return isArray(array) ? array : copy(array);
}

export function head<T>(array: ArrayLike<T>): T | null {
export function first<T>(array: ArrayLike<T>): T | null {
return array.length === 0 ? null : array[0];
}

/** @deprecated Use {@link first} instead. */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore duplicate identifier: This is the exported declaration, the implementation is below.
export function head<T>(array: ArrayLike<T>): T | null;

/** @internal This implementation is for internal use only, the exported declaration is above */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore duplicate identifier: This is the actual implementation, the exported declaration is above.
const head = first;

export function tail<T>(array: ArrayLike<T>): T[] {
return nativeSlice.call(array, 1);
}
Expand Down

0 comments on commit 2a723e9

Please sign in to comment.