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.

34 lines
952 B

4 years ago
  1. import _curry2 from "./internal/_curry2.js";
  2. import _reduce from "./internal/_reduce.js";
  3. import keys from "./keys.js";
  4. /**
  5. * An Object-specific version of [`map`](#map). The function is applied to three
  6. * arguments: *(value, key, obj)*. If only the value is significant, use
  7. * [`map`](#map) instead.
  8. *
  9. * @func
  10. * @memberOf R
  11. * @since v0.9.0
  12. * @category Object
  13. * @sig ((*, String, Object) -> *) -> Object -> Object
  14. * @param {Function} fn
  15. * @param {Object} obj
  16. * @return {Object}
  17. * @see R.map
  18. * @example
  19. *
  20. * const xyz = { x: 1, y: 2, z: 3 };
  21. * const prependKeyAndDouble = (num, key, obj) => key + (num * 2);
  22. *
  23. * R.mapObjIndexed(prependKeyAndDouble, xyz); //=> { x: 'x2', y: 'y4', z: 'z6' }
  24. */
  25. var mapObjIndexed =
  26. /*#__PURE__*/
  27. _curry2(function mapObjIndexed(fn, obj) {
  28. return _reduce(function (acc, key) {
  29. acc[key] = fn(obj[key], key, obj);
  30. return acc;
  31. }, {}, keys(obj));
  32. });
  33. export default mapObjIndexed;