-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
forEachObjIndexed.js
37 lines (35 loc) · 1.09 KB
/
forEachObjIndexed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import _curry2 from './internal/_curry2.js';
import keys from './keys.js';
/**
* Iterate over an input `object`, calling a provided function `fn` for each
* key and value in the object.
*
* `fn` receives three argument: *(value, key, obj)*.
*
* @func
* @memberOf R
* @since v0.23.0
* @category Object
* @sig ((a, String, StrMap a) -> Any) -> StrMap a -> StrMap a
* @param {Function} fn The function to invoke. Receives three argument, `value`, `key`, `obj`.
* @param {Object} obj The object to iterate over.
* @return {Object} The original object.
* @example
*
* const printKeyConcatValue = (value, key) => console.log(key + ':' + value);
* R.forEachObjIndexed(printKeyConcatValue, {x: 1, y: 2}); //=> {x: 1, y: 2}
* // logs x:1
* // logs y:2
* @symb R.forEachObjIndexed(f, {x: a, y: b}) = {x: a, y: b}
*/
var forEachObjIndexed = _curry2(function forEachObjIndexed(fn, obj) {
var keyList = keys(obj);
var idx = 0;
while (idx < keyList.length) {
var key = keyList[idx];
fn(obj[key], key, obj);
idx += 1;
}
return obj;
});
export default forEachObjIndexed;