Skip to content

Commit

Permalink
Add head as alias for first
Browse files Browse the repository at this point in the history
  • Loading branch information
paldepind committed Oct 9, 2019
1 parent ad65402 commit 83bba02
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/curried.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
of,
empty,
first,
head,
last,
flatten,
pop,
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,13 @@ export function first<A>(l: List<A>): A | undefined {
: undefined;
}

/**
* Alias for [`first`](#first).
*
* @category Folds
*/
export const head = first;

/**
* Returns the last element of the list. If the list is empty the
* function returns `undefined`.
Expand Down
3 changes: 3 additions & 0 deletions src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare module "./index" {
append(value: A): List<A>;
intersperse(separator: A): List<A>;
first(): A | undefined;
head(): A | undefined;
last(): A | undefined;
map<B>(f: (a: A) => B): List<B>;
pluck<K extends keyof A>(key: K): List<A[K]>;
Expand Down Expand Up @@ -121,6 +122,8 @@ List.prototype.first = function<A>(): A | undefined {
return L.first(this);
};

List.prototype.head = List.prototype.first;

List.prototype.last = function<A>(): A | undefined {
return L.last(this);
};
Expand Down
1 change: 1 addition & 0 deletions src/ramda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const repeat = curry(L.repeat);
export const times = curry(L.times);
export const length = curry(L.length);
export const first = curry(L.first);
export const head = first;
export const last = curry(L.last);
export const nth = curry(L.nth);
export const map = curry(L.map);
Expand Down

0 comments on commit 83bba02

Please sign in to comment.