Lazy
Defined in: src/util/Lazy.ts:33
Type Parameters
Section titled “Type Parameters”T
Accessors
Section titled “Accessors”isEvaluated
Section titled “isEvaluated”Get Signature
Section titled “Get Signature”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.
Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”flatMap()
Section titled “flatMap()”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.
Type Parameters
Section titled “Type Parameters”U
Parameters
Section titled “Parameters”(value) => Lazy<U>
Returns
Section titled “Returns”Lazy<U>
forEach()
Section titled “forEach()”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.
Parameters
Section titled “Parameters”(value) => void
Returns
Section titled “Returns”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.
Returns
Section titled “Returns”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.
Type Parameters
Section titled “Type Parameters”U
Parameters
Section titled “Parameters”(value) => U
Returns
Section titled “Returns”Lazy<U>
peek()
Section titled “peek()”peek():
T|undefined
Defined in: src/util/Lazy.ts:79
Return the cached value if already evaluated, else undefined.
Returns
Section titled “Returns”T | undefined
reset()
Section titled “reset()”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.
Returns
Section titled “Returns”void
setOverride()
Section titled “setOverride()”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.
Parameters
Section titled “Parameters”T | null
Returns
Section titled “Returns”void
evaluated()
Section titled “evaluated()”
staticevaluated<T>(value):Lazy<T>
Defined in: src/util/Lazy.ts:43
Build a lazy cell that’s already evaluated to value (no thunk runs).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”Lazy<T>
staticof<T>(compute):Lazy<T>
Defined in: src/util/Lazy.ts:40
Build a lazy cell from a thunk. Preferred entry point.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”compute
Section titled “compute”() => T
Returns
Section titled “Returns”Lazy<T>