Skip to content

Lazy

Defined in: src/util/Lazy.ts:33

T

get isEvaluated(): boolean

Defined in: src/util/Lazy.ts:74

true once .get() can return without running the thunk — either the thunk has already been executed (success or failure both count), or an override is active. false only in the initial pending state.

boolean

flatMap<U>(f): Lazy<U>

Defined in: src/util/Lazy.ts:96

Derive a new Lazy whose value flattens a Lazy<Lazy<U>>. Same laziness contract as map.

U

(value) => Lazy<U>

Lazy<U>


forEach(f): void

Defined in: src/util/Lazy.ts:104

Run a side effect against the evaluated value. Forces evaluation; idempotent by virtue of the cache.

(value) => void

void


get(): T

Defined in: src/util/Lazy.ts:54

Get the memoised value. Runs the thunk on first call; subsequent calls return the cached result. If the thunk threw, the same error is re-thrown on every subsequent access.

T


map<U>(f): Lazy<U>

Defined in: src/util/Lazy.ts:88

Derive a new Lazy whose value is f(this.get()). The derivation is itself lazy — map(f) does not force the source.

U

(value) => U

Lazy<U>


peek(): T | undefined

Defined in: src/util/Lazy.ts:79

Return the cached value if already evaluated, else undefined.

T | undefined


reset(): void

Defined in: src/util/Lazy.ts:112

Forget the memoised value so the next get() re-runs the thunk. Primarily a test hook — also clears any override set via setOverride. In hot production paths, prefer building a new Lazy rather than resetting.

void


setOverride(value): void

Defined in: src/util/Lazy.ts:122

Test hook: force .get() to return value without touching the thunk or the cache. Call reset() (or setOverride(null)) to restore normal evaluation.

T | null

void


static evaluated<T>(value): Lazy<T>

Defined in: src/util/Lazy.ts:43

Build a lazy cell that’s already evaluated to value (no thunk runs).

T

T

Lazy<T>


static of<T>(compute): Lazy<T>

Defined in: src/util/Lazy.ts:40

Build a lazy cell from a thunk. Preferred entry point.

T

() => T

Lazy<T>