bbaldino
05/20/2020, 11:03 PMFoo (which I don't control) which exposes a field incoming: ReceiveChannel<String>, and I have a custom type data class MyType(val str: String) and I want to add an extension field to Foo to expose a field incomingMyType: ReceiveChannel<MyType>. What's the best way to wrap the existing channel and map it to produce instances of MyType containing the String values? I have something equivalent to the code below working, but wondering if there's any better way. Maybe something with Flow?
val Foo.incomingMyType: ReceiveChannel<MyType>
get() = produce {
for (str in incoming) {
send(MyType(str))
}
}Adam Powell
05/20/2020, 11:53 PMFlow as your extension instead:
val Foo.incomingMyType: Flow<MyType> get() = incoming.receiveAsFlow()
.map { MyType(it) }bbaldino
05/20/2020, 11:55 PMreceiveAsFlow pretty new? I don't seem to have itbbaldino
05/20/2020, 11:56 PMbbaldino
05/20/2020, 11:57 PMbbaldino
05/20/2020, 11:57 PMreceiveAsFlow?)octylFractal
05/21/2020, 12:14 AMAdam Powell
05/21/2020, 12:14 AMoctylFractal
05/21/2020, 12:15 AMAdam Powell
05/21/2020, 12:16 AMkotlinx-coroutines-core version and ktor will happily still use itbbaldino
05/21/2020, 4:29 AMOrhan Tozan
05/28/2020, 6:43 PM