December 2017
Intermediate to advanced
322 pages
7h 3m
English
The startWith operator is simple; it enables you to add an item to the producer at the top of all preexisting items.
Let's take a look at how it works:
fun main(args: Array<String>) {
Observable.range(0,10)//(1)
.startWith(-1)//(2)
.subscribe({
println("Received $it")
})
listOf("C","C++","Java","Kotlin","Scala","Groovy")//(3)
.toObservable()
.startWith("Programming Languages")//(4)
.subscribe({
println("Received $it")
})
}
The output is as follows:

As we can see, the startWith operator on comment (2) and (4) worked just like a prefix on the existing list of emissions.
Read now
Unlock full access