Hullaballoonatic
06/09/2019, 6:13 PMwhen
for just two cases for clarity? e.g.
enum class Foo {
FOO, BAR
}
fun foo(foo: Foo): Int = when(foo) {
FOO -> "foo"
BAR -> "bar"
}
or is this basically a no-no, because an single if
else
can handle it? e.g.
fun foo(foo: Foo) = if (foo == FOO) "foo" else "bar"
Pavlo Liapota
06/09/2019, 6:27 PMwhen
here.Hullaballoonatic
06/09/2019, 6:29 PMwhen
clearer even in non-enum cases:
fun foo(foo: Int) = when(foo) {
2 -> "two"
else -> "not two"
}
Maybe I just like the syntax more, or the way everything lines up. The blocking of it, etcPavlo Liapota
06/09/2019, 6:47 PMif
would not fit into one line, then I would use when
in some cases too 🙂necati
06/09/2019, 7:21 PMHullaballoonatic
06/09/2019, 8:55 PMA -> B
represents if A then B
and so it matches that.