Example 1 — Official greet Helper
Skip the middle argument of R.replace so the template stays fixed and the name comes later.
const greet = R.replace('{name}', R.__, 'Hello, {name}!');
console.log(greet('Alice')); // "Hello, Alice!"
console.log(greet('Bob')); // "Hello, Bob!" How It Works
- Three slots.
R.replaceneeds a pattern, a replacement, and a string. - One gap. The pattern and string are given;
R.__holds the replacement slot open. - Waiting function. With a gap left,
greetis a function, not a string. - Fill it.
greet('Alice')fills the gap, soR.replaceruns →'Hello, Alice!'.
