whereEq.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import _curry2 from "./internal/_curry2.js";
  2. import equals from "./equals.js";
  3. import map from "./map.js";
  4. import where from "./where.js";
  5. /**
  6. * Takes a spec object and a test object; returns true if the test satisfies
  7. * the spec, false otherwise. An object satisfies the spec if, for each of the
  8. * spec's own properties, accessing that property of the object gives the same
  9. * value (in [`R.equals`](#equals) terms) as accessing that property of the
  10. * spec.
  11. *
  12. * `whereEq` is a specialization of [`where`](#where).
  13. *
  14. * @func
  15. * @memberOf R
  16. * @since v0.14.0
  17. * @category Object
  18. * @sig {String: *} -> {String: *} -> Boolean
  19. * @param {Object} spec
  20. * @param {Object} testObj
  21. * @return {Boolean}
  22. * @see R.propEq, R.where
  23. * @example
  24. *
  25. * // pred :: Object -> Boolean
  26. * const pred = R.whereEq({a: 1, b: 2});
  27. *
  28. * pred({a: 1}); //=> false
  29. * pred({a: 1, b: 2}); //=> true
  30. * pred({a: 1, b: 2, c: 3}); //=> true
  31. * pred({a: 1, b: 1}); //=> false
  32. */
  33. var whereEq =
  34. /*#__PURE__*/
  35. _curry2(function whereEq(spec, testObj) {
  36. return where(map(equals, spec), testObj);
  37. });
  38. export default whereEq;