stantronic
02/07/2020, 11:02 AMwhen(someObject){
.hasSomeProperty() -> doSomething
.isBetterThan(someValue) -> doSomethingElse()
else -> doAThirdThing()
}
Where hasSomeProperty() and .isBetterThan are either member or extensions functions on someObjectkioba
02/07/2020, 12:03 PMfun someObject.myEffect() {
when{
hasSomeProperty() -> doSomething
isBetterThan(someValue) -> doSomethingElse()
else -> doAThirdThing()
}
}kioba
02/07/2020, 12:05 PMwhen
when{
someObject.hasSomeProperty() -> doSomething
someObject.isBetterThan(someValue) -> doSomethingElse()
else -> doAThirdThing()
}
why do you think when() with a scope would be a good pick?stantronic
02/07/2020, 5:15 PMCody Engel
02/07/2020, 8:13 PMwith(someObject) {
when {
hasSomeProperty() ->
isBetterThan(someValue) ->
else ->
}
}Cody Engel
02/07/2020, 8:14 PMstantronic
02/10/2020, 10:09 AMLeon K
02/14/2020, 1:41 PMwhen introduce a receiver scope by itself (which has been proposed many times) are about backwards-compatibility and ambiguity. making this a special syntax, where you can use .method() would solve the compabibility problems and would be a great improvement to readability in many cases.
it's also not that far of the currently existing syntax for is, where normally you do if(foo is Bar) but in when you just do when(foo) { is Bar -> {} } which in essence is the exact same idea of just leaving out the variable name within the when clause whilst typing everything else like you'd need to in an if-statement
I'd love and support an actual language proposal for this! go for it, manKy Leggiero
03/20/2020, 5:31 PM