June 2017
Intermediate to advanced
400 pages
8h 44m
English
When none of the collection operators have what you need, you can always use the collect() operator to specify a different type to collect items into. For instance, there is no toSet() operator to collect emissions into a Set<T>, but you can quickly use collect() to effectively do this. You will need to specify two arguments that are built with lambda expressions: initialValueSupplier, which will provide a new HashSetfor a new Observer, and collector, which specifies how each emission is added to that HashSet:
import io.reactivex.Observable;import java.util.HashSet;public class Launcher { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma", "Delta", "Epsilon") .collect(HashSet::new, HashSet::add) . ...
Read now
Unlock full access