UNPKG

ramda-extension

Version:

Helpful functions built on top of the mighty Ramda

25 lines (24 loc) 950 B
import { converge, nthArg, call } from 'ramda'; import dotPath from './dotPath'; import assocDotPath from './assocDotPath'; import headArg from './headArg'; import lastArg from './lastArg'; var resolveDotPath = /*#__PURE__*/converge(dotPath, [headArg, lastArg]); var performMerge = /*#__PURE__*/converge(call, [/*#__PURE__*/nthArg(1), resolveDotPath, /*#__PURE__*/nthArg(2)]); /** * Merge data in object using custom merge fn. * * @func * @category Object * * @param {String} path The dot path to the value * @param {Function} mergeFn The merging function * @param {*} value Value to merge * @param {Object} obj The object to clone * @return {Object} A new object with merge data * @example * * R_.mergeWithDotPath('a.b', R.mergeRight, { d: 30 }, {a: {b: { c: 20 }}}); //=> {a: {b: { c: 20, d: 30 }}} */ var mergeWithDotPath = /*#__PURE__*/converge(assocDotPath, [headArg, performMerge, lastArg]); export default mergeWithDotPath;