You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
951 B

4 years ago
  1. import _curry2 from "./internal/_curry2.js";
  2. /**
  3. * Returns a partial copy of an object containing only the keys that satisfy
  4. * the supplied predicate.
  5. *
  6. * @func
  7. * @memberOf R
  8. * @since v0.8.0
  9. * @category Object
  10. * @sig ((v, k) -> Boolean) -> {k: v} -> {k: v}
  11. * @param {Function} pred A predicate to determine whether or not a key
  12. * should be included on the output object.
  13. * @param {Object} obj The object to copy from
  14. * @return {Object} A new object with only properties that satisfy `pred`
  15. * on it.
  16. * @see R.pick, R.filter
  17. * @example
  18. *
  19. * const isUpperCase = (val, key) => key.toUpperCase() === key;
  20. * R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4}
  21. */
  22. var pickBy =
  23. /*#__PURE__*/
  24. _curry2(function pickBy(test, obj) {
  25. var result = {};
  26. for (var prop in obj) {
  27. if (test(obj[prop], prop, obj)) {
  28. result[prop] = obj[prop];
  29. }
  30. }
  31. return result;
  32. });
  33. export default pickBy;