Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mahdiPourkazemi/5b30e934e1bb48d0636a4f9d5aa6b222 to your computer and use it in GitHub Desktop.
Save mahdiPourkazemi/5b30e934e1bb48d0636a4f9d5aa6b222 to your computer and use it in GitHub Desktop.
remove bracket hell for using flow
//PourkazemiMahdi
fun <T> StateFlow<T>.collectIt(lifecycleOwner: LifecycleOwner, function: (T) -> Unit) {
lifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED){
collect {
function.invoke(it)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment