the type of the "success" branch value
Readonly_Readonly[toReadonlyerrorReturns the success value, or calls the never-returning handler with the Failure's error.
Use this when you have a helper like (msg) => fail(msg, 2) that terminates the program —
the result type is unconditionally T, so you avoid the TypeScript narrowing trap where
if (t.isFailure()) fail(...) fails to narrow t.value when fail is an arrow function
typed as (...): never.
Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success
Function to apply if the Try is Failure
Function to apply if the Try is Success
The result of applying the appropriate function
Async variant of fold. Accepts sync or async handlers on either branch and always returns a Promise.
Returns the contained value or null
Extract the value or throw an error
Returns the contained value or undefined
Converts to a plain readonly array: [value] for Success, [] for Failure.
Symmetric with Try.toList() but skips the List wrapper for code that
just wants to feed Array.prototype methods or spread into another array.
Converts to Either<E, T>. Failure becomes Left(builder(error)) when given a function, or Left(leftValue) when given a value. Success becomes Right(value).
Prefer the function form to thread the underlying Error's context into the Left:
Try.fromYAML(text).toEither((e) => parse failed: ${e.message})
Converts this monad to an Option.
Conversion rules:
Returns a string representation of an object.
Converts this monad to a Try.
Conversion rules:
Custom JSON serialization. Success emits {"@functype":"Try","_tag":"Success","value":T}.
Failure emits {"@functype":"Try","_tag":"Failure","error":SerializedError} where
SerializedError captures name, message, stack, and the full cause chain —
e.name survives round-trip but instanceof SomeError does not.
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
Base interface for sum-type containers (Either, Try, etc.) that are NOT iterables.
Unlike
FunctypeBase, this base deliberately excludesTraversable— which bundlesreduce/reduceRight/size/isEmpty. Those methods force A-invariance on their containers (signature(f: (A, A) => A) => Aputs A in both contravariant and covariant positions) and have no semantic meaning for disjoint-union types where the "success" branch is 0-or-1, not a collection.Sum types that extend
FunctypeSumcan be declared covariant in their type parameter (interface Foo<out A>) without structural check failures. This mirrors Scala's model:Either[+L, +R]andTry[+T]do not extendIterable; onlyOption[+A]extends the lighterIterableOnce[+A].Only the covariance-safe subset of
ContainerOpsis included inline:contains,exists, andforEachall place A only in contravariant (callback input) position.find(returnsOption<A>) andcountare intentionally omitted — if a sum type needs them it can declare them directly.