ResultStream<S, F> class
A deferred source that emits a sequence of Results each time it is run.
Failures are data: a Failure never ends the stream. Operators apply to each result as it arrives. An operator callback that throws turns that event into an untyped stream error, and later events keep flowing. Untyped stream errors pass through every operator.
Constructors
-
ResultStream(Stream<
Result< stream())S, F> > -
A deferred source that emits a sequence of Results each time it is run.
const
-
ResultStream.attempt({required Stream<
S> run(), required F handle(Object e)}) -
Wraps a stream of plain values, catching its errors as failures.
factory
- ResultStream.fail(F value, [Object? exception, StackTrace? stackTrace])
-
Creates a result stream that emits one failure with the given value and
an optional exception and stack trace, then closes. For stubbing in tests:
factory
-
ResultStream.fromResults(Iterable<
Result< results)S, F> > -
Creates a result stream that emits the given results in order, then
closes. For stubbing in tests:
factory
-
ResultStream.fromTask(Task<
S, F> task) -
Creates a result stream that emits the task's Result, then closes.
factory
- ResultStream.succeed(S value)
-
Creates a result stream that emits one success with the given value,
then closes. For stubbing in tests:
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
apply<
S2, F2> (Result< S2, F2> onRun(Result<S, F> result)) → ResultStream<S2, F2> - Maps each whole Result.
-
chain<
S2> (Task< S2, F> task(S success)) → ResultStream<S2, F> - Runs the task built from each success value. Failures skip it.
-
chainStream<
S2> (ResultStream< S2, F> stream(S success)) → ResultStream<S2, F> - Switches to the result stream built from each success value.
-
combineWith<
B, S2> (ResultStream< B, F> other, {required S2 combine(S a, B b)}) → ResultStream<S2, F> -
Combines the latest success of this stream and the others with
combine. -
combineWithFive<
B, C, D, E, G, S2> ((ResultStream< B, F> , ResultStream<C, F> , ResultStream<D, F> , ResultStream<E, F> , ResultStream<G, F> ) others, {required S2 combine(S a, B b, C c, D d, E e, G g)}) → ResultStream<S2, F> -
Combines the latest success of this stream and the others with
combine. -
combineWithFour<
B, C, D, E, S2> ((ResultStream< B, F> , ResultStream<C, F> , ResultStream<D, F> , ResultStream<E, F> ) others, {required S2 combine(S a, B b, C c, D d, E e)}) → ResultStream<S2, F> -
Combines the latest success of this stream and the others with
combine. -
combineWithThree<
B, C, D, S2> ((ResultStream< B, F> , ResultStream<C, F> , ResultStream<D, F> ) others, {required S2 combine(S a, B b, C c, D d)}) → ResultStream<S2, F> -
Combines the latest success of this stream and the others with
combine. -
combineWithTwo<
B, C, S2> ((ResultStream< B, F> , ResultStream<C, F> ) others, {required S2 combine(S a, B b, C c)}) → ResultStream<S2, F> -
Combines the latest success of this stream and the others with
combine. -
convert<
S2> (S2 onSuccess(S success)) → ResultStream< S2, F> - Maps the success value. A failure passes through.
-
convertBoth<
S2, F2> ({required S2 onSuccess(S success), required F2 onFailure(F failure)}) → ResultStream< S2, F2> - Maps the success value and the failure value.
-
convertFailure<
F2> (F2 onFailure(F failure)) → ResultStream< S, F2> - Maps the failure value. A success passes through.
-
ensure(
{required bool check(S success), required F otherwise(S success)}) → ResultStream< S, F> -
Turns a success that fails
checkinto a failure ofotherwise(success). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
recoverWhen(
{required bool check(F failure), required S then(F failure)}) → ResultStream< S, F> -
Turns a failure that passes
checkinto a success ofthen(failure). -
restartWhen(
{bool onFailure(F failure, int attempt)?, bool onClose(int attempt)?, Duration delay(int attempt)?, bool hideFailure = true}) → ResultStream< S, F> -
Cancels the source and runs it again when
onFailureoronClosereturns true, such as to reconnect a dropped websocket feed. -
run(
) → Stream< Result< S, F> > - Runs the source and returns its stream of Results.
-
then<
S2> (FutureOr< Result< run(S success)) → ResultStream<S2, F> >S2, F> - Runs a function that returns a Result with each success value. Failures skip it.
-
thenAttempt<
S2> ({required FutureOr< S2> run(S success), required F handle(Object e)}) → ResultStream<S2, F> - Runs a function that may throw with each success value, catching a throw as Task.attempt does. Failures skip it.
-
thenAttemptStream<
S2> ({required Stream< S2> run(S success), required F handle(Object e)}) → ResultStream<S2, F> - Switches to the plain stream built from each success value, catching its errors as ResultStream.attempt does. Otherwise it behaves like chainStream.
-
toString(
) → String -
A string representation of this object.
inherited
-
transform<
S2, F2> (StreamTransformer< Result< transformer) → ResultStream<S, F> , Result<S2, F2> >S2, F2> -
Applies a StreamTransformer to the results, for stream-shaped behaviour
such as
distinct,takeor debouncing. -
untilFailure(
) → ResultStream< S, F> - Emits results up to and including the first failure, then closes and cancels the source. Untyped stream errors don't stop it.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited