WithPrevious<T> class
A StreamTransformer that pairs each value in a stream with its previous value.
This transformer takes each value from the source stream and emits a record containing both the current value and the previous value. The first emission will have the initialPrevious value, if provided, as the previous value.
The transformed stream emits a PreviousValuePair, which is a record type containing:
previous
: The previous value in the stream (or initialPrevious for the first emission)current
: The current value from the stream
Example:
final stream = Stream.fromIterable([1, 2, 3]);
final withPrevious = stream.transform(WithPrevious(0));
// Emits: (previous: 0, current: 1)
// (previous: 1, current: 2)
// (previous: 2, current: 3)
- Inheritance
-
- Object
- StreamTransformerBase<
T, PreviousValuePair< T> > - WithPrevious
Constructors
- WithPrevious.new([T? initialPrevious])
- Creates a WithPrevious transformer.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialPrevious → T?
-
The initial previous value to use for the first emission.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bind(
Stream< T> stream) → Stream<PreviousValuePair< T> > -
Transforms the provided
stream
.override -
cast<
RS, RT> () → StreamTransformer< RS, RT> -
Provides a
StreamTransformer<RS, RT>
view of this stream transformer.inherited -
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