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

hashCode int
The hash code for this object.
no setterinherited
isErr bool
Tells whether this failed.
no setter
isOk bool
Tells whether this succeeded.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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 if this.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 if this.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

Static Methods

tryCatch<RETURN>(RETURN uncertain()) Result<RETURN, ExTrace>
Runs the given uncertain function and wraps either its RETURN value or its thrown Exception and StackTrace in a Result