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.


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>>();


OfTypeStreamTransformer(TypeToken<S> typeToken)


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


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.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
toString() → String
Returns a string representation of this object.


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