Search code examples
androidkotlinrx-javarx-androidrx-kotlin

mapping custom data RxAndroid with Kotlin


I am trying to convert examples from this article from Java to Kotlin. I get error from picture at Exmaple 5:

enter image description here

And I noticed, that without map() function I don't get this error

enter image description here

So, what the point of this error and how to write it right?


Solution

  • The return value of a lambda in Kotlin is always the last expression in the block.

    So in this case the result of

    .map { it.note = it.note.toUpperCase() }
    

    is not returning a meaningful value.

    What you should do instead is this

    .map { 
        it.note = it.note.toUpperCase()
        it
    }
    

    Which returns a type of Note instead of Unit.