main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | import { curry, over, lensPath, mergeLeft } from 'ramda';
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | * Create a new object with the own properties of the object under the `path`
|
---|
| 5 | * merged with the own properties of the provided `source`.
|
---|
| 6 | * If a key exists in both objects, the value from the `source` object will be used.
|
---|
| 7 | *
|
---|
| 8 | * @func mergePath
|
---|
| 9 | * @memberOf RA
|
---|
| 10 | * @since {@link https://char0n.github.io/ramda-adjunct/1.18.0|v1.18.0}
|
---|
| 11 | * @category Object
|
---|
| 12 | * @sig [k] -> {a} -> {k: {a}} -> {k: {a}}
|
---|
| 13 | * @see {@link RA.mergeProp|mergeProp}
|
---|
| 14 | * @param {!Array} path The property path of the destination object
|
---|
| 15 | * @param {!Object} source The source object
|
---|
| 16 | * @param {!Object} obj The object that has destination object under corresponding property path
|
---|
| 17 | * @return {!Object} The new version of object
|
---|
| 18 | * @example
|
---|
| 19 | *
|
---|
| 20 | * RA.mergePath(
|
---|
| 21 | * ['outer', 'inner'],
|
---|
| 22 | * { foo: 3, bar: 4 },
|
---|
| 23 | * { outer: { inner: { foo: 2 } } }
|
---|
| 24 | * ); //=> { outer: { inner: { foo: 3, bar: 4 } }
|
---|
| 25 | */
|
---|
| 26 | const mergePath = curry((path, source, obj) =>
|
---|
| 27 | over(lensPath(path), mergeLeft(source), obj)
|
---|
| 28 | );
|
---|
| 29 |
|
---|
| 30 | export default mergePath;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.