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 a 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 Result with the result of calling computation.
factory
Result.error(Object error, [StackTrace? stackTrace])
Creates a Result holding an error.
factory
Result.value(T value)
Creates a Result holding 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 Result future.
captureAll<T>(Iterable<FutureOr<T>> elements) Future<List<Result<T>>>
Captures each future in elements,
captureSink<T>(EventSink<Result<T>> sink) EventSink<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<T>> result) Result<T>
Converts a result of a result to a single result.
flattenAll<T>(Iterable<Result<T>> results) Result<List<T>>
Converts a sequence of results to a result of a list.
release<T>(Future<Result<T>> future) Future<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<T>> source) Stream<T>
Releases a stream of source values 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.