Result<OK, ERR> class
Represents an operation which might fail. A safer way to handle operations which might produce a runtime exception. It ensures safety by enforcing the explicit handling of both cases of the operation.
Holds either a value which if type OK
or a value of type ERR
, but never both.
Constructors
- Result.err(ERR err)
-
Produces a Result which failed.
factory
- Result.ok(OK ok)
-
Produces a Result which succeeded.
factory
Properties
Methods
-
err(
ERR fallback) → ERR -
Returns err value if present, else
fallback
. -
errOr(
ERR fallback()) → ERR -
Returns err value if present, else value produced by
fallback
. -
errOrAsync(
Future< ERR> fallback()) → Future<ERR> - Async version of Result.errOr.
-
errUnsafe(
) → ERR? - Returns the err value as nullable. Only use this if necessary.
-
ifErr<
RETURN> (RETURN onErr(ERR err)) → Option< RETURN> -
Calls
onErr
ifthis.isErr
and returns its value in an Option. -
ifErrAsync<
RETURN> (Future< RETURN> onErr(ERR err)) → Future<Option< RETURN> > - Async version of Result.ifErr.
-
ifOk<
RETURN> (RETURN onOk(OK ok)) → Option< RETURN> -
Calls
onOk
ifthis.isOk
and returns its value in an Option. -
ifOkAsync<
RETURN> (Future< RETURN> onOk(OK ok)) → Future<Option< RETURN> > - Async version of Result.ifOk.
-
match<
RETURN> ({required RETURN onOk(OK ok), required RETURN onErr(ERR err)}) → RETURN - Calls the matching function and returns its value.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
ok(
OK fallback) → OK -
Returns ok value if present, else
fallback
. -
okOr(
OK fallback()) → OK -
Returns ok value if present, else value produced by
fallback
. -
okOrAsync(
Future< OK> fallback()) → Future<OK> - Async version of Result.okOr.
-
okUnsafe(
) → OK? - Returns the ok value as nullable. Only use this if necessary.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited