zak.taccardi
01/04/2021, 10:05 PMwhen
?streetsofboston
01/04/2021, 10:07 PMreturn
statement is an expression returning Nothing
.streetsofboston
01/04/2021, 10:09 PMval a: Int = when (value) {
Hello -> 4
There -> 6
Bye -> return null
}
return "$a"
FunkyMuse
01/04/2021, 10:14 PMNir
01/04/2021, 10:48 PMwhen
inside a loop that is used as part of the logic to iterate something, and perhaps one of the cases allows early exitMarc Knaup
01/04/2021, 10:52 PMbreak
then. Except in Kotlin/JS, there you should definitely avoid break
in when
inside a loop 😅Nir
01/04/2021, 11:06 PMNir
01/04/2021, 11:07 PMzak.taccardi
01/05/2021, 2:58 AMzak.taccardi
01/05/2021, 2:59 AMreturn@label
will work for functions, but idk how to label a when
statementzak.taccardi
01/05/2021, 2:59 AMzak.taccardi
01/05/2021, 3:01 AMval exhaustive = when {
exception != null -> {
if (something) {
// return out of when early - does not work
return@when somethingElse
}
// carry on my wayward son
Result.raise(exception)
}
Nir
01/05/2021, 3:53 AMNir
01/05/2021, 3:53 AMNir
01/05/2021, 3:54 AMNir
01/05/2021, 3:54 AMlouiscad
01/05/2021, 10:29 AMbreak
in when
be avoided in Kotlin/JS?Marc Knaup
01/05/2021, 11:34 AMMarc Knaup
01/05/2021, 11:34 AMlouiscad
01/05/2021, 11:49 AMMarc Knaup
01/05/2021, 11:53 AM