Mirror<T> class
abstract
A generic result container that holds either a success value of type T
or an error.
Use MirrorSuccess for successful results, and MirrorFailure for failures.
This class provides convenient methods to work with asynchronous or synchronous operations that can either succeed or fail, without using exceptions.
Example usage:
Mirror<int> success = MirrorSuccess(42);
Mirror<int> failure = MirrorFailure('Error occurred');
success.fold(
onSuccess: (value) => print('Success: $value'),
onFailure: (error) => print('Failure: $error'),
);
failure.fold(
onSuccess: (value) => print('Success: $value'),
onFailure: (error) => print('Failure: $error'),
);
- Implementers
Constructors
- Mirror.new()
-
const
Properties
- errorOrNull → Object?
-
Returns the error or null if this is a success.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isFailure → bool
-
Returns true if this instance represents a failure.
no setter
- isSuccess → bool
-
Returns true if this instance represents a successful result.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- valueOrNull → T?
-
Returns the success value or null if this is a failure.
no setter
Methods
-
delay(
Duration duration) → Future< Mirror< T> > -
Returns a Future that completes with this Mirror after a delay of
duration
. -
fold<
R> ({required R onFailure(Object error), required R onSuccess(T value)}) → R -
Applies
onSuccess
if this is a success, oronFailure
if this is a failure, returning a value of typeR
. -
map<
R> (R transform(T value)) → Mirror< R> -
Transforms the success value using
transform
, or returns the failure unchanged. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onFailureDo(
void fn(Object error)) → void -
Executes the provided
fn
callback if this is a failure. -
onSuccessDo(
void fn(T value)) → void -
Executes the provided
fn
callback if this is a success. -
recover(
T recoverFn(Object error)) → Mirror< T> -
Recovers from failure by transforming the error into a success value using
recoverFn
. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited