Skip to content

Instantly share code, notes, and snippets.

@ThinaticSystem
Created January 31, 2026 06:37
Show Gist options
  • Select an option

  • Save ThinaticSystem/76d8c0eb0db0a6fbb26db97a3523b245 to your computer and use it in GitHub Desktop.

Select an option

Save ThinaticSystem/76d8c0eb0db0a6fbb26db97a3523b245 to your computer and use it in GitHub Desktop.
memoize.js
// @ts-check
"use strict";
/**
* @template T
* @param {() => T} computation
*/
export const memoize = (computation) => {
/** @type {T} */ let cache;
return () => (cache ??= computation());
};
export const memoize = <T>(computation: () => T) => {
let cache: T;
return () => (cache ??= computation());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment