Yusuf Ibragimov
01/06/2024, 7:02 AMfun onValueChange(phone: String) {
viewModelScope.launch {
if (phone.length >= 10) return@launch
if (!phone.onlyNumberCheck()) return@launch
if (uiState.value.screenState == ScreenState.Loading) return@launch
_phone.emit(phone)
}
}
vs
fun onValueChange(phone: String) {
viewModelScope.launch {
if (
phone.length >= 10 ||
!phone.onlyNumberCheck() ||
uiState.value.screenState == ScreenState.Loading
) {
return@launch
}
_phone.emit(phone)
}
}
Which is the most suitable style in this case? one if or 3 line ifascii
01/06/2024, 7:16 AMephemient
01/06/2024, 7:24 AMwhen
?Yusuf Ibragimov
01/06/2024, 7:27 AMPablichjenkov
01/06/2024, 8:14 AMif/else
or the more general when
. I like creating a separate function so it looks 1 line per condition.
In above option I would pick 1
snowstorm6
01/06/2024, 4:46 PMYusuf Ibragimov
01/08/2024, 3:58 AM