Takes a string-returning keyGen and a function fn, then returns a new function that caches results for later calls with the same key (official Ramda docs). On each call, keyGen runs on the same arguments; if that key is already stored, fn is skipped.
Stable since v0.24.0:R.memoizeWith is a core Ramda helper — not deprecated, experimental, or non-standard. It replaced the removed R.memoize. You always supply the key function yourself.
Syntax
Call R.memoizeWith. Start with this line.
Ramda
R.memoizeWith(keyGen, fn)
Call
What it does
R.memoizeWith(keyGen, fn)
Primary signature.
R.memoizeWith(...)
Call the function helper.
Prefer import { memoizeWith } from "ramda" when you want a named import.
Library declarations
Ramda
R.memoizeWith(keyGen, fn)
Parameters
Parameter
Description
keyGen
Required. Turns args into a cache key (string)
fn
Required. Function whose results are cached
Return Value
Return Value
Description
*
Memoized function with the same arity
Ramda Examples
Example 1 — Official Age Cache
Key on birth/death. First call runs fn; same dates return the cache.
Ramda
const withAge = R.memoizeWith(
o => `${o.birth}/${o.death}`,
({ birth, death }) => {
console.log(`computing age for ${birth}/${death}`);
return { birth, death, age: death - birth };
}
);
console.log(JSON.stringify(withAge({ birth: 1921, death: 1999 })));
console.log(JSON.stringify(withAge({ birth: 1921, death: 1999 })));
Equal list. New array, same dump → cache hit; count stays 1.
Different list.[1, 2, 4] → 7; count becomes 2.
Compatibility
Browser & Runtime Support
R.memoizeWith() is ordinary JavaScript once Ramda is loaded. It needs no special browser API — only a JS runtime that can run Ramda v0.24.0+.
✓ Ramda 0.24.0+ · Any JS runtime
Ramda.js R.memoizeWith()
Works in every modern browser and runtime where you can load Ramda 0.24.0 or later (CDN or npm). Older Ramda builds before 0.24.0 do not include memoizeWith; the old R.memoize helper was removed.
100%With Ramda 0.24+
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.memoizeWith()Universal
Bottom line: Safe in any project that includes Ramda 0.24.0 or later. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Bun, and Deno.
Frequently Asked Questions
R.memoizeWith(keyGen, fn) returns a new function that caches fn's results. On each call, keyGen runs on the same arguments and that string becomes the cache key. If the key is already in the cache, fn is skipped. Added in v0.24.0.
withAge uses o => `${o.birth}/${o.death}` as keyGen and returns { birth, death, age: death - birth }. The first withAge({birth: 1921, death: 1999}) computes age 78. The second call with the same dates returns the cached object and does not log 'computing age'.
R.memoize was removed. It tried to stringify every argument for you. memoizeWith makes you pick the key, so you can cache on the fields that matter and avoid accidental collisions.
Yes for a single primitive (numbers, strings). No for objects or multiple arguments: identity keeps only the first argument, and an object used as an object-key becomes '[object Object]', so every object can collide.
No. The cache is a closed-over object. It grows for every new key until the memoized function is discarded. Do not memoize unbounded user input without a bound.
No. R.memoizeWith is a stable Ramda function helper from v0.24.0. It is not deprecated, experimental, or non-standard. It replaced the removed R.memoize.