1 | var _curry2 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry2.js");
|
---|
4 |
|
---|
5 | var _has =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_has.js");
|
---|
8 | /**
|
---|
9 | * Takes a spec object and a test object; each of the spec's own properties must be a predicate function.
|
---|
10 | * Each predicate is applied to the value of the corresponding property of the
|
---|
11 | * test object. `whereAny` returns true if at least one of the predicates return true,
|
---|
12 | * false otherwise.
|
---|
13 | *
|
---|
14 | * `whereAny` is well suited to declaratively expressing constraints for other
|
---|
15 | * functions such as [`filter`](#filter) and [`find`](#find).
|
---|
16 | *
|
---|
17 | * @func
|
---|
18 | * @memberOf R
|
---|
19 | * @since v0.28.0
|
---|
20 | * @category Object
|
---|
21 | * @sig {String: (* -> Boolean)} -> {String: *} -> Boolean
|
---|
22 | * @param {Object} spec
|
---|
23 | * @param {Object} testObj
|
---|
24 | * @return {Boolean}
|
---|
25 | * @see R.propSatisfies, R.where
|
---|
26 | * @example
|
---|
27 | *
|
---|
28 | * // pred :: Object -> Boolean
|
---|
29 | * const pred = R.whereAny({
|
---|
30 | * a: R.equals('foo'),
|
---|
31 | * b: R.complement(R.equals('xxx')),
|
---|
32 | * x: R.gt(R.__, 10),
|
---|
33 | * y: R.lt(R.__, 20)
|
---|
34 | * });
|
---|
35 | *
|
---|
36 | * pred({a: 'foo', b: 'xxx', x: 8, y: 34}); //=> true
|
---|
37 | * pred({a: 'xxx', b: 'xxx', x: 9, y: 21}); //=> false
|
---|
38 | * pred({a: 'bar', b: 'xxx', x: 10, y: 20}); //=> false
|
---|
39 | * pred({a: 'foo', b: 'bar', x: 10, y: 20}); //=> true
|
---|
40 | * pred({a: 'foo', b: 'xxx', x: 11, y: 20}); //=> true
|
---|
41 | */
|
---|
42 |
|
---|
43 |
|
---|
44 | var whereAny =
|
---|
45 | /*#__PURE__*/
|
---|
46 | _curry2(function whereAny(spec, testObj) {
|
---|
47 | for (var prop in spec) {
|
---|
48 | if (_has(prop, spec) && spec[prop](testObj[prop])) {
|
---|
49 | return true;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | return false;
|
---|
54 | });
|
---|
55 |
|
---|
56 | module.exports = whereAny; |
---|