Patrick Ramsey
05/06/2021, 9:41 PMwhen (someFunctionCall()) {
Success -> it.value
Error -> { ... error handling code ... }
}
Right now I’m just explicitly declaring a new variable in the when () clause:
when (val result = someFunctionCall()) { ... }
which works, but feels like cheating. Is this the actual accepted pattern, or is there a better way?Zach Klippenstein (he/him) [MOD]
05/06/2021, 9:42 PMPatrick Ramsey
05/06/2021, 9:43 PMPatrick Ramsey
05/06/2021, 9:43 PMephemient
05/06/2021, 9:48 PMPatrick Ramsey
05/06/2021, 9:49 PMOrhan Tozan
05/06/2021, 10:15 PMPatrick Ramsey
05/06/2021, 10:15 PMPatrick Ramsey
05/06/2021, 10:15 PMNir
05/06/2021, 10:23 PM.let
then you can use ifNir
05/06/2021, 10:23 PMPatrick Ramsey
05/06/2021, 10:23 PMNir
05/06/2021, 10:23 PMif
or when
is more natural, but .let { when(it)
seems unnecessaryPatrick Ramsey
05/06/2021, 10:23 PMPatrick Ramsey
05/06/2021, 10:24 PMwhen (val result = …. )
is a blessed pattern, which I’m more than fine with! Just wanted to make sure