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:
1023 bytes
|
Line | |
---|
1 | var _arrayReduce =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_arrayReduce.js");
|
---|
4 |
|
---|
5 | var _curry2 =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_curry2.js");
|
---|
8 |
|
---|
9 | var keys =
|
---|
10 | /*#__PURE__*/
|
---|
11 | require("./keys.js");
|
---|
12 | /**
|
---|
13 | * An Object-specific version of [`map`](#map). The function is applied to three
|
---|
14 | * arguments: *(value, key, obj)*. If only the value is significant, use
|
---|
15 | * [`map`](#map) instead.
|
---|
16 | *
|
---|
17 | * @func
|
---|
18 | * @memberOf R
|
---|
19 | * @since v0.9.0
|
---|
20 | * @category Object
|
---|
21 | * @sig ((*, String, Object) -> *) -> Object -> Object
|
---|
22 | * @param {Function} fn
|
---|
23 | * @param {Object} obj
|
---|
24 | * @return {Object}
|
---|
25 | * @see R.map
|
---|
26 | * @example
|
---|
27 | *
|
---|
28 | * const xyz = { x: 1, y: 2, z: 3 };
|
---|
29 | * const prependKeyAndDouble = (num, key, obj) => key + (num * 2);
|
---|
30 | *
|
---|
31 | * R.mapObjIndexed(prependKeyAndDouble, xyz); //=> { x: 'x2', y: 'y4', z: 'z6' }
|
---|
32 | */
|
---|
33 |
|
---|
34 |
|
---|
35 | var mapObjIndexed =
|
---|
36 | /*#__PURE__*/
|
---|
37 | _curry2(function mapObjIndexed(fn, obj) {
|
---|
38 | return _arrayReduce(function (acc, key) {
|
---|
39 | acc[key] = fn(obj[key], key, obj);
|
---|
40 | return acc;
|
---|
41 | }, {}, keys(obj));
|
---|
42 | });
|
---|
43 |
|
---|
44 | module.exports = mapObjIndexed; |
---|
Note:
See
TracBrowser
for help on using the repository browser.