Skip to content

Instantly share code, notes, and snippets.

@vitorvigano
Created November 17, 2022 21:33
Show Gist options
  • Save vitorvigano/21debba9fe7a2b4c6834e9e680726e70 to your computer and use it in GitHub Desktop.
Save vitorvigano/21debba9fe7a2b4c6834e9e680726e70 to your computer and use it in GitHub Desktop.
val email = MutableStateFlow("")
val password = MutableStateFlow("")
val isEmailAndPasswordValid = MutableStateFlow(false).apply {
viewModelScope.launch {
combine(email, password) { n1, n2 ->
validate(n1, n2)
}.collect { isValid ->
value = isValid
}
}
}
private fun validate(name: String, password: String) =
name.isNotEmpty() && password.isNotEmpty()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment