February 2020
Intermediate to advanced
412 pages
9h 36m
English
The flatMap() operator has an overloaded version, flatMap(Function<T,Observable<R>> mapper, BiFunction<T,U,R> combiner), that allows the provision of a combiner along with the mapper function. This second combiner function associates the originally emitted T value with each flat-mapped U value and turns both into an R value. We can modify our earlier example of emitting letters from each string and associate each letter with the original string emission it was mapped from:
import io.reactivex.rxjava3.core.Observable;public class Ch4_08 { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma") .flatMap(s -> Observable.fromArray(s.split("")), (s, r) -> s + "-" + r) .subscribe(System.out::println) ...
Read now
Unlock full access