MCPcopy Index your code
hub / github.com/vercel/hyper / memoize

Function memoize

cli/api.ts:33–43  ·  view source on GitHub ↗

* We need to make sure the file reading and parsing is lazy so that failure to * statically analyze the hyper configuration isn't fatal for all kinds of * subcommands. We can use memoization to make reading and parsing lazy.

(fn: T)

Source from the content-addressed store, hash-verified

31 * subcommands. We can use memoization to make reading and parsing lazy.
32 */
33function memoize<T extends (...args: any[]) => any>(fn: T): T {
34 let hasResult = false;
35 let result: any;
36 return ((...args: any[]) => {
37 if (!hasResult) {
38 result = fn(...args);
39 hasResult = true;
40 }
41 return result;
42 }) as T;
43}
44
45const getFileContents = memoize(() => {
46 try {

Callers 1

api.tsFile · 0.70

Calls 1

fnFunction · 0.85

Tested by

no test coverage detected