Using ramda
, I'm trying to find (or build) a very trivial operator that expects a function and returns a function that asks for its arguments before returning a new function that makes the actual call. You can think of this as "delaying" the invocation. As pointed out by replies below, this is usually call a thunk
.
Essentially,
const wrap = fn => (...args) => () => fn(...args);
const sayHiWorld = wrap(console.log)('hi', 'world');
sayHiWorld();
// -> 'hi world'
Partial application won't work in my case because args are actually not known at moment of definition. Closest I got was by using R.useWith
- but that restricts the number of arguments.
Any ideas?