Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 8x 8x 9x 2x 8x 8x 8x 7x 8x 8x | import { purry } from './purry';
/**
* Gets the first element of `array`.
* Note: In `pipe`, use `first()` form instead of `first`. Otherwise, the inferred type is lost.
* @param array the array
* @signature
* P.first(array)
* @example
* P.first([1, 2, 3]) // => 1
* P.first([]) // => undefined
* P.pipe(
* [1, 2, 4, 8, 16],
* P.filter(x => x > 3),
* P.first(),
* x => x + 1
* ); // => 5
*
* @category Array, Pipe
*/
export function first<T>(array: readonly T[]): T | undefined;
export function first<T>(): (array: readonly T[]) => T | undefined;
export function first<T>(defaultValue: T): (array: readonly T[]) => T;
export function first() {
return purry(_first, arguments, first.lazy);
}
function _first<T>(array: T[]) {
return array[0];
}
export namespace first {
export function lazy<T>() {
return (value: T) => {
return {
done: true,
hasNext: true,
next: value,
};
};
}
export namespace lazy {
export const single = true;
}
}
|