whereType<S> method

Stream<S> whereType <S>()

This transformer is a shorthand for Stream.where followed by Stream.cast.

Events that do not match T are filtered out, the resulting Stream will be of Type T.

Example

Stream.fromIterable([1, 'two', 3, 'four'])
  .whereType<int>()
  .listen(print); // prints 1, 3

as opposed to:

Stream.fromIterable([1, 'two', 3, 'four'])
  .where((event) => event is int)
  .cast<int>()
  .listen(print); // prints 1, 3

Implementation

Stream<S> whereType<S>() => transform(WhereTypeStreamTransformer<T, S>());