Vsevolod Tolstopyatov | 74bcc92 | 2018-05-03 20:07:54 +0300 | [diff] [blame] | 1 | package cases.whenMappings |
| 2 | |
| 3 | sealed class SampleSealed { |
| 4 | class A : SampleSealed() |
| 5 | class B : SampleSealed() |
| 6 | class C : SampleSealed() |
| 7 | } |
| 8 | |
| 9 | fun SampleSealed.deacronimize() = when (this) { |
| 10 | is SampleSealed.A -> "Apple" |
| 11 | is SampleSealed.B -> "Biscuit" |
| 12 | is SampleSealed.C -> "Cinnamon" |
| 13 | } |
| 14 | |
| 15 | |
| 16 | inline 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 | } |