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