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

Ok

An Ok can be created with a value

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

Constructors

Ok(T value)
Ok

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value → T
Value when a Result is ok,
final

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