Make code more readable

This commit is contained in:
Kirill Kamakin
2022-04-08 22:08:21 +05:00
parent a3d320bb79
commit 869fa21e3f
3 changed files with 8 additions and 15 deletions

View File

@@ -2,7 +2,6 @@ package gq.kirmanak.mealient.extensions
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
@@ -10,8 +9,4 @@ import kotlinx.coroutines.launch
inline fun <T> Fragment.collectWithViewLifecycle(
flow: Flow<T>,
crossinline collector: suspend (T) -> Unit,
) = launchWithViewLifecycle { flow.collect(collector) }
fun Fragment.launchWithViewLifecycle(
block: suspend CoroutineScope.() -> Unit,
) = viewLifecycleOwner.lifecycleScope.launch(block = block)
) = viewLifecycleOwner.lifecycleScope.launch { flow.collect(collector) }