mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
11 lines
205 B
TypeScript
11 lines
205 B
TypeScript
export function memo<T>(fn: () => T) {
|
|
let value: T | undefined
|
|
let loaded = false
|
|
|
|
return (): T => {
|
|
if (loaded) return value as T
|
|
loaded = true
|
|
value = fn()
|
|
return value as T
|
|
}
|
|
}
|