1 | import _curry3 from "./internal/_curry3.js";
|
---|
2 | import modifyPath from "./modifyPath.js";
|
---|
3 | /**
|
---|
4 | * Creates a copy of the passed object by applying an `fn` function to the given `prop` property.
|
---|
5 | *
|
---|
6 | * The function will not be invoked, and the object will not change
|
---|
7 | * if its corresponding property does not exist in the object.
|
---|
8 | * All non-primitive properties are copied to the new object by reference.
|
---|
9 | *
|
---|
10 | * @func
|
---|
11 | * @memberOf R
|
---|
12 | * @since v0.28.0
|
---|
13 | * @category Object
|
---|
14 | * @sig Idx -> (v -> v) -> {k: v} -> {k: v}
|
---|
15 | * @param {String|Number} prop The property to be modified.
|
---|
16 | * @param {Function} fn The function to apply to the property.
|
---|
17 | * @param {Object} object The object to be transformed.
|
---|
18 | * @return {Object} The transformed object.
|
---|
19 | * @example
|
---|
20 | *
|
---|
21 | * const person = {name: 'James', age: 20, pets: ['dog', 'cat']};
|
---|
22 | * R.modify('age', R.add(1), person); //=> {name: 'James', age: 21, pets: ['dog', 'cat']}
|
---|
23 | * R.modify('pets', R.append('turtle'), person); //=> {name: 'James', age: 20, pets: ['dog', 'cat', 'turtle']}
|
---|
24 | */
|
---|
25 |
|
---|
26 | var modify =
|
---|
27 | /*#__PURE__*/
|
---|
28 | _curry3(function modify(prop, fn, object) {
|
---|
29 | return modifyPath([prop], fn, object);
|
---|
30 | });
|
---|
31 |
|
---|
32 | export default modify; |
---|