Skip to main content
Module

x/ramda/source/whereAny.js

:ram: Practical functional Javascript
Latest
File
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 * @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;