The Observable.from methods
The Observable.from
methods are comparatively simpler than the Observable.create
method. You can create the Observable
instances from nearly every Kotlin structure with the help of from methods.
Note
In RxKotlin 1, you will have Observale.from
as a method; however, from RxKotlin 2.0 (as with RxJava2.0), operator overloads have been renamed with a postfix, such as fromArray
, fromIterable
, and fromFuture
.
Let's take a look at the following code:
fun main(args: Array<String>) { val observer: Observer<String> = object : Observer<String> { override fun onComplete() { println("Completed") } override fun onNext(item: String) { println("Received-> $item") } override fun onError(e: Throwable) { println("Error Occured => ${e.message}") } override fun onSubscribe(d: Disposable) { println("Subscription") } }//Create...