December 2017
Intermediate to advanced
322 pages
7h 3m
English
With imperative programming, we have the ability to access the nth element of any array/list, which is quite a common requirement. The elementAt operator is really helpful in this regard; it pulls the nth element from the producer and emits it as its own sole emission.
Take a look at the following piece of code:
fun main(args: Array<String>) {
val observable = listOf(10,1,2,5,8,6,9)
.toObservable()
observable.elementAt(5)//(1)
.subscribe { println("Received $it") }
observable.elementAt(50)//(2)
.subscribe { println("Received $it") }
}
Take a look at the following output before we continue to inspect the code:

On comment ...
Read now
Unlock full access