Filtering emissions - filter operator

The filter operator is arguably the most used filtering/suppressing operator. It lets you implement custom logic to filter emissions.

The following code snippet is the simplest implementation of the filter operator:

    fun main(args: Array<String>) { 
      Observable.range(1,20)//(1) 
        .filter{//(2) 
          it%2==0 
     }
.subscribe { println("Received $it") } }

On comment (1), we created an Observable instance with the help of the Observable.range() operator. We filtered out odd numbers from the emissions with the help of the filter operator on comment (2).

The following is the output:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.235.176