Rx Kotlin: map function can't infer return type

In your map function replace the statement

return socket

with

return@map socket

Because return statement is normally used to return values for top-level functions. For lambda expressions and inline (nested) functions, use returns at labels i.e. return@{method_name}. You can also leave last line just to socket in the case, and the compiler will handle it for you assuming the last line as return value for the inline function. But for better readability, I will definitely prefer qualified return syntax. You can read more details in kotlin documentation here and here