flatMapIterable<S> method

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

Converts each item into a new 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.


Observable.range(1, 4)
  .flatMapIterable((i) =>
    new Observable.just([i])
  .listen(print); // prints 1, 2, 3, 4


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