Readonly_Readonly[toReturns the right value, or calls the never-returning handler with the Left's value.
Use this when you have a helper like (msg) => fail(msg, 2) that terminates the
program — the result type is unconditionally R, so you avoid the TypeScript
narrowing trap where if (e.isLeft()) fail(...) fails to narrow e.value when
fail is an arrow function typed as (...): never.
Applies a predicate to the Right value. If the predicate fails, short-circuits
to a Left carrying the value produced by onUnsatisfied. Left passes through
unchanged (predicate not evaluated). Lets you turn a value-level guard into the
Left channel without breaking the chain with an if/return Left(...) ladder.
Chains an async function that returns an Either. A Left resolves unchanged.
If f rejects or throws, the returned Promise rejects with the same reason, as with mapAsync.
Async variant of fold. Accepts sync or async handlers on either branch and always returns a Promise, keeping chains fluent when at least one branch is async.
ReadonlymapMaps the Right value with an async function. A Left resolves unchanged.
If f rejects or throws, the returned Promise rejects with the same reason: it does not
become a Left, and it never throws synchronously. To turn a rejection into a Left, use Either.fromPromise(p, onRejected)
or tryCatchAsync, which take a function from the reason to L.
Returns the contained value or null
Returns the Right value, or throws on a Left. Pass an Error to throw it, or a builder to make one
from the Left value — for code that must throw for a host (a retrying step runner, an MCP tool, a
React Query queryFn). With no argument, throws the Left value itself.
Returns the contained value or undefined
Converts this monad to an Option.
Conversion rules:
Returns a string representation of an object.
ReadonlyvalueConverts this monad to an Either.
Conversion rules:
(err: Error) => E to thread the underlying Error's context into the Left.The value to use for the Left case when the source is empty/none/failure
An Either with the value as Right or the provided leftValue as Left
Custom JSON serialization that excludes getter properties.
Emits the canonical functype envelope with @functype: "Either" so
native JSON.stringify recursion (e.g. inside a plain object body)
produces a marker-bearing envelope that survives a round-trip through
Serialization.deserialize.
Converts this container to a Promise
The behavior depends on the implementing container:
A Promise that resolves or rejects based on the container's state
Converts this monad to a Try.
Conversion rules:
A Try containing Success with the value or Failure with an appropriate error
Right variant of Either. Discriminated by
_tag: "Right"withvalue: R.