How to use the state of one observable to skip values of another observable?
<p>This is best explained with a short example.<br>
let's say this is my source observable that I want to filter</p>

<pre><code>Observable.interval(1, TimeUnit.SECONDS)
</code></pre>

<p>I use a checkbox to handle the filter state. When the box is not checked, I want to skip all values.<br>
I use RxAndroid to get an observable for the checkbox like this:</p>

<pre><code>RxCompoundButton.checkedChanges(checkBox)
</code></pre>

<p>here is my code:</p>

<pre><code>    Observable.combineLatest(
            RxCompoundButton.checkedChanges(checkBox)
            , Observable.interval(1, TimeUnit.SECONDS)
            , (isChecked, intervalCounter) -&gt; {
                if (!isChecked) {
                    return null;
                } else {
                    return intervalCounter;
                }
            }
    ).filter(Objects::nonNull)
</code></pre>

<p>and I get the desired output</p>

<pre><code>interval       1--2--3--4--5--6--7--8--9  
checkbox       0-----1--------0-----1---
combineLatest
result         ------3--4--5--------8--9
</code></pre>

<p>I am just getting started with RxJava and my "solution" does not feel right, because:<br>
You can see that the combine function returns a magic value <code>null</code> and then the filter will skip these <code>nulls</code>.<br>
That means that the filter function is called even though I already know, that I want to skip this data.</p>

<ul>
<li>maybe I should use another operator</li>
<li>is there a way to use the checkbox-observable in a filter function</li>
<li>maybe there is some way in the combine function to signal that I want to skip this data</li>
</ul>