forked from Tinkoff/utils.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anyPass.ts
30 lines (28 loc) · 917 Bytes
/
anyPass.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
import { anyPass } from '../typings/types';
import curryN from './curryN';
/**
* Takes a list of predicates and returns a predicate that returns true for a
* given list of arguments if at least one of the provided predicates is satisfied
* by those arguments.
*
* @param {Array} fns predicates
* @param {...*} args passed arguments to predicates
* @return {Function}
* @example
*
* var isClub = propEq('rank', '♣');
* var isSpade = propEq('suit', '♠︎');
* var isBlackCard = anyPass([isClub, isSpade]);
*
* isBlackCard({rank: '10', suit: '♣'}); //=> true
* isBlackCard({rank: 'Q', suit: '♠'}); //=> true
* isBlackCard({rank: 'Q', suit: '♦'}); //=> false
*/
export default curryN(2, (fns, ...args) => {
for (let i = 0; i < fns.length; i++) {
if (fns[i](...args)) {
return true;
}
}
return false;
}) as typeof anyPass;