UNPKG

1.17 kBJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2");
4
5var keys =
6/*#__PURE__*/
7require("./keys");
8/**
9 * Iterate over an input `object`, calling a provided function `fn` for each
10 * key and value in the object.
11 *
12 * `fn` receives three argument: *(value, key, obj)*.
13 *
14 * @func
15 * @memberOf R
16 * @since v0.23.0
17 * @category Object
18 * @sig ((a, String, StrMap a) -> Any) -> StrMap a -> StrMap a
19 * @param {Function} fn The function to invoke. Receives three argument, `value`, `key`, `obj`.
20 * @param {Object} obj The object to iterate over.
21 * @return {Object} The original object.
22 * @example
23 *
24 * const printKeyConcatValue = (value, key) => console.log(key + ':' + value);
25 * R.forEachObjIndexed(printKeyConcatValue, {x: 1, y: 2}); //=> {x: 1, y: 2}
26 * // logs x:1
27 * // logs y:2
28 * @symb R.forEachObjIndexed(f, {x: a, y: b}) = {x: a, y: b}
29 */
30
31
32var forEachObjIndexed =
33/*#__PURE__*/
34_curry2(function forEachObjIndexed(fn, obj) {
35 var keyList = keys(obj);
36 var idx = 0;
37
38 while (idx < keyList.length) {
39 var key = keyList[idx];
40 fn(obj[key], key, obj);
41 idx += 1;
42 }
43
44 return obj;
45});
46
47module.exports = forEachObjIndexed;
\No newline at end of file