Result<T extends Object, E extends Exception> class sealed

Result

Result has two variants: Ok and Err

final Result<String, Exception> result =
switch(result) {
  return switch (this) {
    Ok(:T value) => value,
    Err(:E err) => throw err,
  };
}

Ok

An Ok can be created with a value

final ok1 = Ok<String, Exception>('Hi');
final ok2 = Result<String, Exception>.ok('Hi');

Err

An Err can be created with an exception

final err1 = Result<String, Exception>.err(Exception('Unexpected'));
final err2 = Err<String, Exception>(Exception('Unexpected'));
Implementers

Constructors

Result.err(E err)
Err
factory
Result.ok(T value)
Ok
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

map<U extends Object>(U onOk(T)) Result<U, E>
Maps the value from T to U if it is Ok, else, keeps the Err, E.
mapErr<E2 extends Exception>(E2 onErr(E)) Result<T, E2>
Maps the error from E to E2 if it is Err, else, keeps the Ok, T.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
unwrap() → T
Unsafe operations that returns T or throw E
unwrapErr() → E
Unsafe operations that returns E or throw an Exception
unwrapOrNull() → T?
Returns T on Ok, or null on Err

Operators

operator ==(Object other) bool
The equality operator.
inherited