source: node_modules/ramda/es/whereAny.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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