Result<T> class
abstract
The result of a computation.
Capturing a result (either a returned value or a thrown error) means converting it into a Result - either a ValueResult or an ErrorResult.
This value can release itself by writing itself either to an EventSink or a Completer, or by becoming a Future.
A Future represents a potential result, one that might not have been computed yet, and a Result is always a completed and available result.
- Implementers
Constructors
- Result(T computation())
-
Creates a
Resultwith the result of callingcomputation.factory - Result.error(Object error, [StackTrace? stackTrace])
-
Creates a
Resultholding an error.factory - Result.value(T value)
-
Creates a
Resultholding a value.factory
Properties
- asError โ ErrorResult?
-
If this is an error result, returns itself.
no setter
-
asFuture
โ Future<
T> -
A future that has been completed with this result as a value or an error.
no setter
-
asValue
โ ValueResult<
T> ? -
If this is a value result, returns itself.
no setter
- hashCode โ int
-
The hash code for this object.
no setterinherited
- isError โ bool
-
Whether this result is an error result.
no setter
- isValue โ bool
-
Whether this result is a value result.
no setter
- runtimeType โ Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addTo(
EventSink< T> sink) โ void - Adds this result to an EventSink.
-
complete(
Completer< T> completer) โ void - Completes a completer with this result.
-
noSuchMethod(
Invocation invocation) โ dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) โ String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) โ bool -
The equality operator.
inherited
Static Methods
-
capture<
T> (Future< T> future) โ Future<Result< T> > -
Captures the result of a future into a
Resultfuture. -
captureAll<
T> (Iterable< FutureOr< elements) โ Future<T> >List< Result< >T> > -
Captures each future in
elements, -
captureSink<
T> (EventSink< Result< sink) โ EventSink<T> >T> -
Captures the events of the returned sink into results on
sink. -
captureStream<
T> (Stream< T> source) โ Stream<Result< T> > - Captures the results of a stream into a stream of Result values.
-
flatten<
T> (Result< Result< result) โ Result<T> >T> - Converts a result of a result to a single result.
-
flattenAll<
T> (Iterable< Result< results) โ Result<T> >List< T> > - Converts a sequence of results to a result of a list.
-
release<
T> (Future< Result< future) โ Future<T> >T> - Releases the result of a captured future.
-
releaseSink<
T> (EventSink< T> sink) โ EventSink<Result< T> > -
Releases results added to the returned sink as data and errors on
sink. -
releaseStream<
T> (Stream< Result< source) โ Stream<T> >T> -
Releases a stream of
sourcevalues into a stream of the results.
Constants
-
captureSinkTransformer
โ const StreamSinkTransformer<
Object, Result< Object> > - A sink transformer that captures events into Results.
-
captureStreamTransformer
โ const StreamTransformer<
Object, Result< Object> > - A stream transformer that captures a stream of events into Results.
-
releaseSinkTransformer
โ const StreamSinkTransformer<
Result< Object> , Object> - A sink transformer that releases result events.
-
releaseStreamTransformer
โ const StreamTransformer<
Result< Object> , Object> - A stream transformer that releases a stream of result events.