-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
whereAny.js
47 lines (45 loc) · 1.47 KB
/
whereAny.js
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 _curry2 from './internal/_curry2.js';
import _has from './internal/_has.js';
/**
* Takes a spec object and a test object; each of the spec's own properties must be a predicate function.
* Each predicate is applied to the value of the corresponding property of the
* test object. `whereAny` returns true if at least one of the predicates return true,
* false otherwise.
*
* `whereAny` is well suited to declaratively expressing constraints for other
* functions such as [`filter`](#filter) and [`find`](#find).
*
* @func
* @memberOf R
* @since v0.28.0
* @category Object
* @sig {String: (* -> Boolean)} -> {String: *} -> Boolean
* @param {Object} spec
* @param {Object} testObj
* @return {Boolean}
* @see R.propSatisfies, R.where
* @example
*
* // pred :: Object -> Boolean
* const pred = R.whereAny({
* a: R.equals('foo'),
* b: R.complement(R.equals('xxx')),
* x: R.gt(R.__, 10),
* y: R.lt(R.__, 20)
* });
*
* pred({a: 'foo', b: 'xxx', x: 8, y: 34}); //=> true
* pred({a: 'xxx', b: 'xxx', x: 9, y: 21}); //=> false
* pred({a: 'bar', b: 'xxx', x: 10, y: 20}); //=> false
* pred({a: 'foo', b: 'bar', x: 10, y: 20}); //=> true
* pred({a: 'foo', b: 'xxx', x: 11, y: 20}); //=> true
*/
var whereAny = _curry2(function whereAny(spec, testObj) {
for (var prop in spec) {
if (_has(prop, spec) && spec[prop](testObj[prop])) {
return true;
}
}
return false;
});
export default whereAny;