Anuta Vlad Sv
12/07/2022, 8:46 AMinline fun <A> Flow<A>.bindState(
lifecycleOwner: LifecycleOwner,
crossinline bind: suspend (A) -> Unit,
) =
lifecycleOwner.lifecycleScope.launchWhenStarted {
collect(bind)
}
Recently I've updated the coroutines library to 1.6.4 (from 1.5.2) and looks like Flow.collect(crossinline action: suspend (value: T) -> Unit)
doesn't work with the newer version of coroutines dependencies. Flow.collect()
now takes a FlowCollector
functional interface argument instead of a suspend (T) -> Unit
. Any suggestions of how I can still keep this as an inline function?Anuta Vlad Sv
12/07/2022, 8:46 AMinline fun <A> Flow<A>.bindState(
lifecycleOwner: LifecycleOwner,
crossinline action: suspend (A) -> Unit,
) =
lifecycleOwner.lifecycleScope.launchWhenStarted {
collect(object : FlowCollector<A> {
override suspend fun emit(value: A) = action(value)
})
}
Sam
12/07/2022, 8:55 AMcollect
function, though 😞.Sam
12/07/2022, 8:55 AMFlowCollector(action)
should work instead of the anonymous object