简体   繁体   English

RxJava2 中的条件过滤器

[英]Conditional filter in RxJava2

I have a method with a signature我有一个带有签名的方法

void supplyData(String query, Integer skip, Integer count)

Typically I would model the method body like this:通常,我会像这样对方法主体进行建模:

MyProvider.observable(query)
 .skip(skip)
  .take(count)
  .subscribe();

Now the two Integers could be null, so I don't need to skip and take all.现在这两个整数可能为空,所以我不需要跳过并全部取走。 How can I make these two steps optional?我怎样才能让这两个步骤成为可选的?

null check should work here, null检查应该在这里工作,

MyProvider.observable(query)
 .skip(skip == null? 0: skip)
 .take(count == null? Integer.MAX_VALUE: count)
 .subscribe();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM