🤖 Generated with [OpenCode](https://opencode.ai) Co-Authored-By: OpenCode <noreply@opencode.ai>
12 lines
188 B
TypeScript
12 lines
188 B
TypeScript
export function lazy<T>(fn: () => T) {
|
|
let value: T | undefined
|
|
let loaded = false
|
|
|
|
return (): T => {
|
|
if (loaded) return value as T
|
|
value = fn()
|
|
return value as T
|
|
}
|
|
}
|
|
|