Created
May 23, 2022 18:22
-
-
Save mahdiPourkazemi/5b30e934e1bb48d0636a4f9d5aa6b222 to your computer and use it in GitHub Desktop.
remove bracket hell for using flow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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