RxJava2 Flowable 条件操作符 any

目录

any(条件操作符)

any图解

any测试用例

any测试用例说明

any实用场景


any(条件操作符

Single<Boolean> any(Predicate<? super T> predicate)

如果源Publisher发出的任何项满足指定条件,则返回发出true的Single,否则返回false。

any图解

any测试用例

 private void doAny() {
        Flowable.just(1,2,3,4,5).any(new Predicate<Integer>() {
            @Override
            public boolean test(Integer integer) throws Exception {
                if(integer < 2) {
                    return true;
                }
                return false;
            }
        }).subscribe(new Consumer<Boolean>() {
            @Override
            public void accept(Boolean aBoolean) throws Exception {
                
            }
        });
    }


测试结果:
10-03 08:05:55.650 4425-4425/hq.demo.net I/System.out: ######doAny#####
10-03 08:05:55.670 4425-4425/hq.demo.net I/System.out: accept aBoolean = true

any测试用例说明

any操作符对Publisher发射的项目进行一一判断,只要有满足条件的的项目就返回true,都不满足则返回false

any实用场景

(后面完善)

猜你喜欢

转载自blog.csdn.net/weixin_36709064/article/details/82936475
今日推荐