Mikael Alfredsson
11/24/2020, 6:23 AMclass FlowGroup<T>(
items:List<MutableSharedFlow<T>>,
transform: suspend (Array<T>) -> T
) {
val flow = MutableSharedFlow<T>()
init {
MainScope().launch {
combine(items, transform).collect {
flow.emit(it)
}
}
}
}
combine
wont compile in this code because it uses the reified
qualifier, and I don’t know how to get that into this function. Any suggestions?Manuel Wrage
11/24/2020, 11:44 AMclass FlowGroup<T> private constructor(combinedFlow: Flow<T>) {
val flow = MutableSharedFlow<T>()
init {
MainScope().launch {
combinedFlow.collect {
flow.emit(it)
}
}
}
companion object {
inline operator fun <reified T> invoke(
items:List<MutableSharedFlow<T>>,
noinline transform: suspend (Array<T>) -> T
) = FlowGroup<T>(combine(items, transform))
}
}
Mikael Alfredsson
11/24/2020, 12:08 PMopen
class the code starts to get quite weird 🙂 Do you know why the combine function that takes a list of flow
as input has to be reified
(the ones with defined number of input flows are not)Manuel Wrage
11/24/2020, 3:10 PMcombine
function calls arrayOfNulls<T>
and the T
of it is also marked as reified
.Mikael Alfredsson
11/24/2020, 3:11 PM