-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
partialObject.js
33 lines (31 loc) · 1.29 KB
/
partialObject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import mergeDeepRight from './mergeDeepRight.js';
import _curry2 from './internal/_curry2.js';
/**
* Takes a function `f` and an object, and returns a function `g`.
* When applied, `g` returns the result of applying `f` to the object
* provided initially merged deeply (right) with the object provided as an argument to `g`.
*
* @func
* @memberOf R
* @since v0.28.0
* @category Function
* @sig (({ a, b, c, ..., n }) -> x) -> { a, b, c, ...} -> ({ d, e, f, ..., n } -> x)
* @param {Function} f
* @param {Object} props
* @return {Function}
* @see R.partial, R.partialRight, R.curry, R.mergeDeepRight
* @example
*
* const multiply2 = ({ a, b }) => a * b;
* const double = R.partialObject(multiply2, { a: 2 });
* double({ b: 2 }); //=> 4
*
* const greet = ({ salutation, title, firstName, lastName }) =>
* salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
*
* const sayHello = R.partialObject(greet, { salutation: 'Hello' });
* const sayHelloToMs = R.partialObject(sayHello, { title: 'Ms.' });
* sayHelloToMs({ firstName: 'Jane', lastName: 'Jones' }); //=> 'Hello, Ms. Jane Jones!'
* @symb R.partialObject(f, { a, b })({ c, d }) = f({ a, b, c, d })
*/
export default _curry2((f, o) => (props) => f.call(this, mergeDeepRight(o, props)));