Example 1 — Official Greeting
Lock the title and name; pass only the salutation later. This is the sample from the Ramda docs.
const greet = (salutation, title, firstName, lastName) =>
salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!';
const greetMsJaneJones = R.partialRight(greet, ['Ms.', 'Jane', 'Jones']);
console.log(greetMsJaneJones('Hello')); // "Hello, Ms. Jane Jones!" How It Works
- Lock.
['Ms.', 'Jane', 'Jones']is stored for the last three parameters. - Call.
'Hello'is the only new argument, so it goes first. - Join. Ramda runs
greet('Hello', 'Ms.', 'Jane', 'Jones'). - Reuse.
greetMsJaneJones('Hi')works too — only the salutation changes.
