/
length.ts
45 lines (40 loc) · 970 Bytes
/
length.ts
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
import { purry } from "./purry";
type Enumerable<T> = ArrayLike<T> | Iterable<T>;
/**
* Counts values of the collection or iterable.
*
* @param items - The input data.
* @signature
* R.length(array)
* @example
* R.length([1, 2, 3]) // => 3
* @dataFirst
* @category Array
*/
export function length<T>(items: Enumerable<T>): number;
/**
* Counts values of the collection or iterable.
*
* @signature
* R.length()(array)
* @example
* R.pipe([1, 2, 3], R.length()) // => 3
* @dataLast
* @category Array
*/
export function length<T>(): (items: Enumerable<T>) => number;
/**
* Counts values of the collection or iterable.
*
* @signature
* R.length()(array)
* @example
* R.pipe([1, 2, 3], R.length()) // => 3
* @category Array
*/
export function length(): unknown {
return purry(_length, arguments);
}
function _length<T>(items: Enumerable<T>): number {
return "length" in items ? items.length : Array.from(items).length;
}