Flow Extensions
Collect
fun <T> Flow<T>.collect(
lifecycleOwner: LifecycleOwner,
lifecycleState: Lifecycle.State = Lifecycle.State.STARTED,
function: (T) -> Unit
) {
lifecycleOwner.lifecycleScope.launch {
lifecycleOwner.repeatOnLifecycle(lifecycleState) {
collect {
function(it)
}
}
}
}