June 2017
Intermediate to advanced
400 pages
8h 44m
English
The filter() operator accepts Predicate<T> for a given Observable<T>. This means that you provide it a lambda that qualifies each emission by mapping it to a Boolean value, and emissions with false will not go forward.
For instance, you can use filter() to only allow string emissions that are not five characters in length:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma", "Delta", "Epsilon") .filter(s -> s.length() != 5) subscribe(s -> System.out.println("RECEIVED: " + s)); }}
The output of the preceding code snippet is as follows:
RECEIVED: BetaRECEIVED: Epsilon
The filter() function is probably the most commonly used operator to suppress ...
Read now
Unlock full access