Sorting emissions (sorted operator)

There are some scenarios where you would like to sort the emissions. The sorted operator helps you do that. It will internally collect and reemit all the emissions from the source producer after sorting.

Let's take a look at this example and try to understand this operator better:

 fun main(args: Array<String>) { println("default with integer") listOf(2,6,7,1,3,4,5,8,10,9) .toObservable() .sorted()//(1) .subscribe { println("Received $it") } println("default with String") listOf("alpha","gamma","beta","theta") .toObservable() .sorted()//(2) .subscribe { println("Received $it") } println("custom sortFunction with integer") listOf(2,6,7,1,3,4,5,8,10,9) .toObservable() .sorted { item1, item2 -> if(item1>item2) ...

Get Reactive Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.