How to terminate the source observable from Observer's onNext method
<p>I wonder what is the best way to terminate the source observable from Observer's onNext method.</p>

<p>For example, I want that a button event emits only once when the validation would be OK. However, when the validation would be failed, a button event can emit again.</p>

<p>What I can think of is below.</p>

<pre><code>Observable....
    .subscribe(new Subscriber(){
        public void onNext(T t){
            // do something and terminate the Observable
            // only when the validate method return true
            if (validate(t)){
                 doSomething(t);
                 unsubscribe();
            }
         }
         ...
     });
</code></pre>

<p>However, if I need an onCompleted event, it doesn't work.
Moreover, I'm not sure about calling <code>onCompleted()</code> from Observer's <code>onNext()</code></p>

<p>Also, I think that to bring the validation into Observable would be not a good idea since Observer must have the responsibility of validation.
Moreover, in the case of "Hot" Observable, the validation might be different from each Observer if the observable has some observers.</p>