41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
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 =
|
|
/*#__PURE__*/
|
|
_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; |