blob: ca82d416d2a144d9f4c7c06a03ebaacc7a951ea9 [file] [log] [blame]
Vsevolod Tolstopyatov74bcc922018-05-03 20:07:54 +03001package cases.whenMappings
2
3sealed class SampleSealed {
4 class A : SampleSealed()
5 class B : SampleSealed()
6 class C : SampleSealed()
7}
8
9fun SampleSealed.deacronimize() = when (this) {
10 is SampleSealed.A -> "Apple"
11 is SampleSealed.B -> "Biscuit"
12 is SampleSealed.C -> "Cinnamon"
13}
14
15
16inline fun SampleSealed.switch(thenA: () -> Unit, thenB: () -> Unit, thenC: () -> Unit) = when (this) {
17 is SampleSealed.C -> thenC()
18 is SampleSealed.B -> thenB()
19 is SampleSealed.A -> thenA()
20}