Lodash _.partialRight() method
What you’ll learn
- How
_.partialRightanchors arguments at the tail of the call. - How invocation arguments fill the leading slots before merged partials.
- How partialRight pairs with
partialRight.placeholderfor mixed tails. - How this compares to
_.partial,_.curryRight, and_.bind.
Prerequisites
Read _.partial(), _.curryRight(), and the Function hub first.
- Partial application: building functions by fixing some parameters.
- Argument order: knowing which parameter sits left versus right.
Overview
_.partialRight(func, ...partials) merges caller-supplied arguments with trailing literals—perfect when APIs reserve dynamic values on the left and constants or callbacks on the right.
Syntax
_.partialRight(func, ...partials)- func: target invoker.
- partials: trailing partial arguments applied after runtime inputs.
- returns: wrapped function performing the merged call.
Freeze the trailing name
Classic lodash pattern: supply greeting later while locking name.
import partialRight from "lodash/partialRight";
function greet(greeting, name) {
return greeting + " " + name;
}
const greetAda = partialRight(greet, "Ada");
greetAda("Hello"); // "Hello Ada"Fix the denominator
Pass the numerator at invoke time while keeping the divisor constant.
import partialRight from "lodash/partialRight";
function divide(a, b) {
return a / b;
}
const overTen = partialRight(divide, 10);
overTen(55); // 5.5Anchor two trailing segments
Useful when filenames share extensions or locales.
import partialRight from "lodash/partialRight";
function joinTriple(head, middle, tail) {
return [head, middle, tail].join(".");
}
const localeBundle = partialRight(joinTriple, "en", "json");
localeBundle("messages"); // "messages.en.json"📋 _.partialRight vs _.partial vs _.curryRight
| Helper | Merge direction | Pick when |
|---|---|---|
_.partialRight | Call-site args first, partials appended | You freeze suffix parameters |
_.partial | Partials precede call-site args | You freeze prefix parameters |
_.curryRight | Accept arguments right-to-left across calls | You want staged invocation until arity fills |
Pitfalls to avoid
Mixing sentinel imports
Match partialRight.placeholder to the same module graph as partialRight; do not splice in partial.placeholder unless docs confirm equivalence.
thisObject methods
partialRight does not fix this; bind first when you wrap prototypes.
Variadic surprises
Extra trailing arguments from callers still flow through—document expectations when wrapping variadic APIs.
❓ FAQ
Summary
- Purpose:
_.partialRightpins trailing parameters while leaving leading slots open. - Contrast: flip mental model from
partial—arguments arrive from the left, constants glue onto the right. - Next: Lodash _.rearg(), revisit Lodash _.partial(), or read official _.partialRight docs.
Because _.partialRight shares Lodash’s createWrap machinery with partial, placeholder tokens resolve through the same replaceHolders pass—only the merge direction flips so preset values anchor the tail of the argument list.
6 people found this page helpful
