Hi all, I am using Spring Webflux and I need some ...
# spring
d
Hi all, I am using Spring Webflux and I need some help getting some code to compile
Copy code
interface Base

data class Derived(val value: String): Base

fun getDerived(): Mono<Derived> = TODO()

fun getBase(): Mono<Base> = getDerived() // this line does not compile

fun getBase2(): Mono<Base> = getDerived().map { it } // this compiles fine
I am new to kotlin so I might be missing something. But is it possible to get the 4th line to compile without mapping it again? If this isn’t the right place to ask this please let me know the appropriate channel. Thanks!
t
I'd recommend against using Mono with Webflux. In Webflux + Kotlin, you can use suspend functions, which is a lot more ergonomic
👍 2
j
Change:
Copy code
fun getBase(): Mono<Base> = getDerived() // this line does not compile
to:
Copy code
fun getBase(): Mono<out Base> = getDerived()
d
thanks Ramon, that fixed the issue. thanks Tristan, I’ll explore using coroutines instead with webflux.