Getting the only item from single or maybe - blockingGet

When you're working with single or maybe, you just can't use any other blocking operator other than blockingGet(). The reason is quite simple, both monads can contain only one item.

So, let's create two new test cases by modifying the last test case as follows:

 @Test fun `test Single with blockingGet`() { val observable = listOf(2,10,5,6,9,8,7,1,4,3).toObservable() .sorted() val firstElement:Single<Int> = observable.first(0) val firstItem = firstElement.blockingGet() assertEquals(1,firstItem) } @Test fun `test Maybe with blockingGet`() { val observable = listOf(2,10,5,6,9,8,7,1,4,3).toObservable() .sorted() val firstElement:Maybe<Int> = observable.firstElement() val firstItem = firstElement.blockingGet() ...

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.