Result<T, E> class

Result is a type that that represents either success (ok) or failure (err)

Examples

Basic usage:

class FallibleOpSuccess {}
class FallibleOpFailure {}

Result<FallibleOpSuccess, FallibleOpFailure> fallibleOp() {
  if (true) {
    return ok(FallibleOpSuccess());
  } else {
    return err(FallibleOpFailure());
  }
}

final result = fallibleOp();

result.inspect((value) {
    print('Success with value: $value');
  }).inspectErr((error) {
    print('Failure with error: $error');
  });
}
Available Extensions
Annotations
  • @immutable

Constructors

Result.err(E errValue)
Failure Result
const
Result.ok(T okValue)
Success Result
const

Properties

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

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object? other) bool
The equality operator.
override