deep-map-with-key
v1.0.1
Published
Creates a new functor with the results of calling a provided function on every element in the calling functor and its key
Downloads
4
Readme
deep-map-with-key
Creates a new functor with the results of calling a provided function on every element in the calling functor and its key
Install
$ npm install deep-map-with-key
Usage
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 } }
API
deepMapWithKey ⇒ Object
| Array
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 } }
License
MIT © saxjst