forked from remeda/remeda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
allPass.ts
47 lines (43 loc) · 1.29 KB
/
allPass.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
46
47
import { purry } from './purry';
/**
* Determines whether all predicates returns true for the input data.
* @param data The input data for predicates.
* @param fns The list of predicates.
* @signature
* R.allPass(data, fns)
* @example
* const isDivisibleBy3 = (x: number) => x % 3 === 0
* const isDivisibleBy4 = (x: number) => x % 4 === 0
* const fns = [isDivisibleBy3, isDivisibleBy4]
* R.allPass(12, fns) // => true
* R.allPass(8, fns) // => false
* @data_first
* @category Array
*/
export function allPass<T>(
data: T,
fns: ReadonlyArray<(data: T) => boolean>
): boolean;
/**
* Determines whether all predicates returns true for the input data.
* @param fns The list of predicates.
* @signature
* R.allPass(fns)(data)
* @example
* const isDivisibleBy3 = (x: number) => x % 3 === 0
* const isDivisibleBy4 = (x: number) => x % 4 === 0
* const fns = [isDivisibleBy3, isDivisibleBy4]
* R.allPass(fns)(12) // => true
* R.allPass(fns)(8) // => false
* @data_last
* @category Array
*/
export function allPass<T>(
fns: ReadonlyArray<(data: T) => boolean>
): (data: T) => boolean;
export function allPass() {
return purry(_allPass, arguments);
}
function _allPass(data: any, fns: Array<(data: any) => boolean>) {
return fns.every(fn => fn(data));
}