官术网_书友最值得收藏!

filter()

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: Beta
RECEIVED: Epsilon

The filter() function is probably the most commonly used operator to suppress emissions.

Note that if all emissions fail to meet your criteria, the returned Observable will be empty, with no emissions occurring before onComplete() is called.
主站蜘蛛池模板: 武平县| 广宗县| 密山市| 肃宁县| 白朗县| 建始县| 台南县| 泰顺县| 洞口县| 门头沟区| 连城县| 砀山县| 旬邑县| 中方县| 平塘县| 华蓥市| 赞皇县| 呼伦贝尔市| 湖北省| 竹溪县| 玉林市| 大新县| 平原县| 郎溪县| 蒙城县| 鞍山市| 肇庆市| 常山县| 华亭县| 五指山市| 长乐市| 秦皇岛市| 南开区| 桃江县| 缙云县| 汉中市| 宁远县| 旅游| 武胜县| 吐鲁番市| 吉水县|