Result<T> class sealed

A sealed monadic wrapper representing the outcome of an operation that can either be a successful evaluation (_SuccessResult) or a structural breakdown (_FailureResult).

By modeling errors as values instead of throwing exceptions, it enforces compile-time exhaustive pattern matching, enhancing domain execution reliability.

Constructors

Result.failure(Failure failure)
Encapsulates the given domain failure description object into an error state container.
factory
Result.success(T value)
Encapsulates the provided value into a successful computation state wrapper.
factory

Properties

failureOrNull Failure?
Yields the contained structured Failure representation if the operation failed; otherwise, returns null.
no setter
hashCode int
Computes a precise hash configuration based on the underlying variant type hash calculation.
no setteroverride
isFailure bool
Evaluates true if this runtime instance encapsulates a caught data failure state.
no setter
isSuccess bool
Evaluates true if this runtime instance encapsulates an underlying successful operation outcome.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
successOrNull Success<T>?
Exposes the comprehensive immutable Success wrapper envelope if applicable; otherwise, yields null.
no setter
valueOrNull → T?
Unwraps and yields the domain value payload directly if the execution succeeded; otherwise, returns null.
no setter

Methods

flatMap<R>(Result<R> transform(T value)) Result<R>
Chains sequential asynchronous or synchronous monadic operations where the transform callback yields another encapsulated Result envelope.
fold<R>({required R onSuccess(T value), required R onFailure(Failure failure)}) → R
Collapses the dual state of this result wrapper into a uniform type R.
getOrElse(T defaultValue) → T
Returns the embedded success value payload directly if present, otherwise fallbacks onto the statically provided defaultValue.
getOrElseFn(T orElse(Failure failure)) → T
Returns the embedded success value payload directly if present, otherwise invokes the functional lazy callback orElse passing down the underlying structural failure context.
getOrThrow() → T
Forces extraction of the underlying value or transforms a domain failure into a terminal runtime state exception.
map<R>(R transform(T value)) Result<R>
Transforms the inner success value type using the provided transform mapper callback function.
mapFailure(Failure transform(Failure failure)) Result<T>
Transforms the underlying domain failure signature using the provided error transform closure.
match<R>({required R onSuccess(Success<T> success), required R onFailure(Failure failure)}) → R
Performs state matching similarly to fold, but explicitly passes the underlying granular Success context object rather than just its unwrapped value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
Maps the string display format dynamically reflecting the current active subtype variant.
override

Operators

operator ==(Object other) bool
Implements deep state structural equality validation across distinct Result wrappers.
override

Static Methods

combine<T>(List<Result<T>> results) Result<List<T>>
Evaluates an array list collection of multi-source results.
fromNullable<T>(T? value, {required String errorMessage}) Result<T>
Evaluates a nullable value reference. Converts to Result.success if the target object is present, otherwise allocates an explicit Failure mapped to the fallback errorMessage.
guard<T>(T operation()) Result<T>
Wraps a synchronous functional code operation executing inside a localized boundary context.
guardAsync<T>(Future<T> operation()) Future<Result<T>>
Wraps an asynchronous code execution operation tracking a standard Dart Future pipeline.
partition<T>(List<Result<T>> results) → (List<T>, List<Failure>)
Partitions a non-homogeneous list collection of results into separated, isolated collections.