flatMapIterable<S> method

Observable<S> flatMapIterable <S>(Stream<Iterable<S>> mapper(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.

Example

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

Implementation

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