Creates a new functor with the results of calling a provided function on every element in the calling functor and its key
$ npm install deep-map-with-key
const { deepMapWithKey } = require("deep-map-with-key");
const double = (number) => number * 2;
const cart = {
rice: 2,
fruits: {
apple: 4,
orange: 8
}
}
};
deepMapWithKey(double, cart); //=> { rice: 4, fruits: { apple: 8, orange: 16 } }
Creates a new functor with the results of calling a provided function on every element in the calling functor and its key
Returns: Object
| Array
- Returns a new value after applying rules
Sig: ((String, *) -> *) -> Object | Array -> Object | Array
Param | Type | Description |
---|---|---|
fn | function |
The function to be called on every element of the input list |
functor | Object | Array |
The functor to iterate over |
Example
const cart = { rice: 2, fruits: { apple: 4, orange: 8 } } };
const double = (number) => number * 2;
deepMapWithKey(double, cart); //=> { rice: 4, fruits: { apple: 8, orange: 16 } }
MIT © muceres