We got introduced to the startWith operator in the previous chapter, but there's still a lot to cover. This operator also lets you combine multiple producers. Take a look at the following example:
fun main(args: Array<String>) { println("startWith Iterator") Observable.range(5,10) .startWith(listOf(1,2,3,4))//(1) .subscribe { println("Received $it") } println("startWith another source Producer") Observable.range(5,10) .startWith(Observable.just(1,2,3,4))//(2) .subscribe { println("Received $it") } }
We can pass another source Observable or an Iterator instance to be prepended before the source Observable that the operator has subscribed to starts emitting.
In the preceding program, on comment (1), we used the startWith ...