OfTypeStreamTransformer<T, S> class

Filters a sequence so that only events of a given type pass

In order to capture the Type correctly, it needs to be wrapped in a TypeToken as the generic parameter.

Given the way Dart generics work, one cannot simply use the is T / as T checks and castings within OfTypeStreamTransformer itself. Therefore, the TypeToken class was introduced to capture the type of class you'd like ofType to filter down to.

Examples

new Stream.fromIterable([1, "hi"])
  .ofType(new TypeToken<String>)
  .listen(print); // prints "hi"

As a shortcut, you can use some pre-defined constants to write the above in the following way:

new Stream.fromIterable([1, "hi"])
  .transform(new OfTypeStreamTransformer(kString))
  .listen(print); // prints "hi"

If you'd like to create your own shortcuts like the example above, simply create a constant:

const TypeToken<Map<Int, String>> kMapIntString =
  const TypeToken<Map<Int, String>>();

Constructors

OfTypeStreamTransformer(TypeToken<S> typeToken)

Properties

transformer → StreamTransformer<T, S>
final
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

Methods

bind(Stream<T> stream) → Stream<S>
Transforms the provided stream. [...]
cast<RS, RT>() → StreamTransformer<RS, RT>
Provides a StreamTransformer<RS, RT> view of this stream transformer.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator.
inherited