mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 05:32:09 +03:00
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/forEachObjIndexed.js
|
|
|
|
|
|
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;
|