A helper that turns a function into a thunk maker: you give it the arguments now, and it hands back a zero-argument function (a thunk) that runs the real call later. The saved arguments live in a closure.
Status: added in Ramda v0.26.0 — stable, not deprecated, experimental, or non-standard.
Syntax
Call R.thunkify. Start with this line.
Ramda
R.thunkify(fn)(…args)()
Call
What it does
R.thunkify(fn)(…args)()
Primary signature.
R.thunkify(...)
Call the function helper.
Prefer import { thunkify } from "ramda" when you want a named import.
Library declarations
Ramda
R.thunkify(fn)(…args)()
Parameters
This helper has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
The value returned by R.thunkify().
Ramda Examples
Example 1 — Official Samples
Save the arguments, then run with the final ().
Ramda
console.log(R.thunkify(R.identity)(42)());
// → 42
console.log(R.thunkify((a, b) => a + b)(25, 17)());
// → 42
R.thunkify was added in Ramda v0.26.0. Ramda’s browser build is plain ES5, so it runs in any modern browser and in Node.js / Bun / Deno with npm install ramda.
✓ Stable · Ramda 0.26.0+
R.thunkify()
Check your Ramda version first — this helper is missing before 0.26.0. The examples use ES2015 arrow functions and let, supported by every evergreen browser.
100%With Ramda 0.26.0+
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
R.thunkifyRamda 0.26.0+
Bottom line: Safe for production with Ramda 0.26.0 or newer. On older builds R.thunkify is undefined; write () => fn(a, b) by hand instead. The labs on this page use [email protected].
Frequently Asked Questions
R.thunkify(fn) lets you give fn its arguments now and run it later. R.thunkify(fn)(a, b) saves the arguments and returns a thunk — a function with no parameters. Calling thunk() runs fn(a, b). The docs sample: R.thunkify((a, b) => a + b)(25, 17)() //=> 42.
R.partial(fn, [a])(b) runs fn as soon as the last argument arrives. R.thunkify(fn)(a, b) does not run fn yet — it returns a thunk, and you need one more () to run it. Both preset arguments; only thunkify delays the call.
R.thunkify(fn) waits for fn's arguments. Once they are all supplied, you get back a zero-argument function (the thunk). The final () calls that thunk, which applies the saved arguments to fn.
No. Every thunk() call runs fn again with the same saved arguments. To run the work only once, wrap the thunk with R.once: R.once(R.thunkify(fn)(a)).
No. JavaScript evaluates arguments when you pass them, so R.thunkify(f)(heavy()) runs heavy() immediately. Only the call to f is delayed. Put the expensive work inside f if it must wait.
No. R.thunkify has been a stable Ramda function helper since v0.26.0 — not deprecated, experimental, or non-standard.