mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 11:45:26 +03:00
1.2 KiB
1.2 KiB
partialRight
Creates a function that invokes func
with partialArgs
appended to the arguments it receives.
This method is like partial, except that partially applied arguments are appended to the arguments it receives.
The partialRight.placeholder
value, which defaults to a symbol
, may be used as a placeholder for partially applied arguments.
Note: This method doesn't set the length
property of partially applied functions.
Signature
function partialRight<F extends Function>(func: F, ...partialArgs: any[]): F;
namespace partialRight {
placeholder: symbol;
}
Parameters
func
(F
): The function to partially apply arguments to.partialArgs
(any[]
, optional): The arguments to be partially applied.
Returns
(F
): Returns the new partially applied function.
Examples
import { partialRight } from 'es-toolkit/function';
function greet(greeting, name) {
return greeting + ' ' + name;
}
const greetFred = partialRight(greet, 'fred');
greetFred('hi');
// => 'hi fred'
// Partially applied with placeholders.
const sayHelloTo = partialRight(greet, 'hello', partialRight.placeholder);
sayHelloTo('fred');
// => 'hello fred'