Err<T extends Object, E extends Exception> class

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,
  };
}

Err

An Err can be created with an exception

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

Constructors

Err(E err)
Err

Properties

err → E
Exception in the Result
final
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.
inherited
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.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override
unwrap() → T
Unsafe operations that returns T or throw E
inherited
unwrapErr() → E
Unsafe operations that returns E or throw an Exception
inherited
unwrapOrNull() → T?
Returns T on Ok, or null on Err
inherited

Operators

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