Search code examples
javareactivex

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?


Solution

  • null check should work here,

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