flatMapIterable<S> method

Stream<S> flatMapIterable <S>(
  1. Stream<Iterable<S>> mapper(
    1. T value

Converts each item into a Stream. The Stream must return an Iterable. Then, each item from the Iterable will be emitted one by one.

Use case: you may have an API that returns a list of items, such as a Stream<List>. However, you might want to operate on the individual items rather than the list itself. This is the job of flatMapIterable.


RangeStream(1, 4)
  .flatMapIterable((i) => Stream.fromIterable([[i]])
  .listen(print); // prints 1, 2, 3, 4


Stream<S> flatMapIterable<S>(Stream<Iterable<S>> Function(T value) mapper) =>
    transform(FlatMapStreamTransformer<T, Iterable<S>>(mapper))
        .expand((Iterable<S> iterable) => iterable);