mapping custom data RxAndroid with Kotlin

百般思念 提交于 2020-01-06 05:08:11

问题


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

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/53509536/mapping-custom-data-rxandroid-with-kotlin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!