How hard for compiler it would be to not ask final...
# compiler
e
How hard for compiler it would be to not ask final
else
case for
Copy code
fun getText(ignoreOptions: Boolean, option: Option): String { 
    return when {
        ignoreOptions -> "Ignored"
        option is OptionA -> "A: ${option.number}"
        option is OptionB -> option.text
    }
}
When Option sealed class and has only OptionA and OptionB as implementations
1
oke probably it is open
when
if it would be something like
when(ingoredOption, option){}
to give copmpiler glimpse it is only things I'm interested here.
b
Copy code
fun getText(ignoreOptions: Boolean, option: Option): String {
  if (ignoreOptions) return "Ignored"

  when (option) {
    is OptionA -> "A: ${option.number}"
    is OptionB -> option.text
  }
}
👍🏼 1
v
s/when/return when/
🙂
y
This is already possible with when guards:
Copy code
fun getText(ignoreOptions: Boolean, option: Option): String { 
    return when (option) {
        else if ignoreOptions -> "Ignored"
        is OptionA -> "A: ${option.number}"
        is OptionB -> option.text
    }
}
K 1
v
Since which language version is that valid syntax?
Ah, 2.1 preview 2.2 stable
TIL