Understanding the toObservable extension function

Thanks to the extension functions of Kotlin, you can turn any Iterable instance, such as List, to Observable without much effort; we have already used this method in Chapter 1A Short Introduction to Reactive Programming, however, take a look at this:

    fun main(args: Array<String>) { 
 
      val observer: Observer<String> = object : Observer<String> { 
        override fun onComplete() { 
            println("All Completed") 
        } 
 
        override fun onNext(item: String) { 
            println("Next $item") 
        } 
 
        override fun onError(e: Throwable) { 
            println("Error Occured ${e.message}") 
        } 
 
        override fun onSubscribe(d: Disposable) { 
            println("New Subscription ") 
        } 
      }//Create Observer 
 
      val list:List<String> = listOf ("String 1","String 2","String 3","String ...

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.