ramda-extension
Version:
Helpful functions built on top of the mighty Ramda
27 lines (26 loc) • 857 B
JavaScript
import { identity, lensPath, useWith } from 'ramda';
import mapOver from './mapOver';
/**
* Maps over a specific path on a list of objects, it returns a new list of objects
*
* @func
* @category List
*
* @param {string[]} path The path to be modified.
* @param {Function} fn The function to be called on every specified path element of the `list`.
* @param {Array} list The list to be iterated over.
* @return {Array} The new list.
*
* @example
*
* const objs = [
* { value: { id: 1 } },
* { value: { id: 2 } },
* ];
* const valueLens = R.lensProp("value");
* R_.mapOverPath(["value", "id"], R.add(100), objs) // [{ value: { id: 101 } }, { value: { id: 102 } }]
*
* @sig string[] -> (* -> *) -> [object] -> [object]
*/
var mapOverPath = /*#__PURE__*/useWith(mapOver, [lensPath, identity, identity]);
export default mapOverPath;