OptionallastValue: AOptionalmessage: stringReadonly_Optional ReadonlylastReadonlymaxStaticisRuntime type guard. Narrows an unknown (or wider) value to
RepeatExhausted<A> when the tag matches. Use this to recover typed
exhaustion when the E channel has collapsed to unknown — a common
situation when the step effect is lifted from a Promise via IO(...) or
IO.async(...). See the class-level JSDoc for a full example.
The type parameter A is an unchecked assertion — the guard confirms the
shape is a RepeatExhausted, but cannot verify lastValue matches A at
runtime. Callers pass the state/value type they expect the loop to have
been producing.
Error surfaced by value-driven repeat combinators when the iteration bound is reached without the predicate being satisfied. Carries the last observed value so callers can report what the loop settled on.
Type parameter
Ais the value type the loop was producing (or the state type forIO.iterate).Narrowing when
EisunknownIf the step effect has
E = unknown(common when lifting a Promise viaIO(() => ...)orIO.async(...)— see the JSDoc on those constructors), TypeScript's union algebra collapsesunknown | RepeatExhausted<A>back tounknown, andRepeatExhausted<A>is lost from the surface type. The runtime behavior is still correct (theRepeatExhaustedinstance is in theLeftat runtime — see reporter's JSON in issue #221) — but consumers need a narrowing step to recover it. UseRepeatExhausted.is:Example
The alternative — annotating
step's error channel soEis a concrete tagged type — also works and preservesRepeatExhausted<A>in the union:Example