https://kotlinlang.org logo
Title
o

orangy

10/26/2018, 4:00 PM
it
cannot be added, because it can change a meaning of some
it
already used
1
r

Ruckus

10/26/2018, 4:02 PM
Out of curiosity, if you could go back and change the design from the get-go, would you use the 1.3 design or an have
when
use a more lambda-ish syntax?
when (getData()) { data ->
   data is Thing -> ...
   ...
}
Which could then use
it
o

orangy

10/26/2018, 4:10 PM
I didn’t try to design it from ground up, so I don’t have an answer. But personally, I’d try to make it possible so that
when
is actually a function 🙂
e

elizarov

10/26/2018, 4:20 PM
Support for when-like functions is still a possibility, imo. Can be retrofitted in a backwards-compatible way. I find use-cases for that from time time.
4
r

Ruckus

10/26/2018, 4:24 PM
@orangy Fair enough. That could be interesting.
@elizarov Do you mean like the coroutine select expressions?
e

elizarov

10/26/2018, 4:25 PM
things like that. but not only that.
It is about alegebraic types with internally encapsulated structure.
So, we support it for product types. If you have an encapsulated color you can destruct it into (r, b, g) via
componentX
operators
But we don’t have that for sum types
r

Ruckus

10/26/2018, 5:20 PM
Ah, okay. Is that something that could be worked around with the new
KClasses.sealdSubclasses
?
l

louiscad

10/26/2018, 6:38 PM
@elizarov Would a custom when like be just a function, or a class, or an interface? Do you think it may be considered in a future Kotlin version? I also had several use cases where I wish I could define a when like construct
o

orangy

10/26/2018, 6:42 PM
No design, no plans, nothing yet
But while we are here, I often want to implement interfaces anonymously in short form like this:
widget.addListener { 
     move -> …
     click -> …
     cancel ->  …
}
where
move
,
click
and
cancel
are methods of the interface that I need to pass to
addListener
. Multi-lambda if you wish.
6
r

Ruckus

10/26/2018, 7:09 PM
@orangy I've wanted something very similar every time I have to do any Swing development.