StreamMaxFuture<T> class

Converts a Stream into a Future that completes with the largest item emitted by the Stream.

This is similar to finding the max value in a list, but the values are asynchronous.

Example

int max = await new StreamMaxFuture(new Stream.fromIterable([1, 2, 3]));

print(max); // prints 3

Example with custom Comparator

Stream<String> stream = new Stream.fromIterable(["short", "loooooooong"]);
Comparator<String> stringLengthComparator = (a, b) => a.length - b.length;
String max = await new StreamMaxFuture(stream, stringLengthComparator);

print(max); // prints "loooooooong"
Inheritance

Constructors

StreamMaxFuture(Stream<T> stream, [Comparator<T> comparator])
Constructs a Future which contains only the largest value emitted by a Stream, optionally using a Comparator to determine that value.

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
wrapped Future<T>
A reference to the wrapped Future.
final, inherited

Methods

asStream() Stream<T>
Creates a Stream containing the result of this future. [...]
inherited
catchError(Function onError, {bool test(Object error)}) Future<T>
Handles errors emitted by this Future. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
then<S>(FutureOr<S> onValue(T value), {Function onError}) Future<S>
Register callbacks to be called when this future completes. [...]
inherited
timeout(Duration timeLimit, {FutureOr<T> onTimeout()}) Future<T>
Time-out the future computation after timeLimit has passed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited
whenComplete(void action()) Future<T>
Registers a function to be called when this future completes. [...]
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited