Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | */ |
| 4 | |
Vsevolod Tolstopyatov | 74bcc92 | 2018-05-03 20:07:54 +0300 | [diff] [blame] | 5 | package cases.whenMappings |
| 6 | |
| 7 | sealed class SampleSealed { |
| 8 | class A : SampleSealed() |
| 9 | class B : SampleSealed() |
| 10 | class C : SampleSealed() |
| 11 | } |
| 12 | |
| 13 | fun SampleSealed.deacronimize() = when (this) { |
| 14 | is SampleSealed.A -> "Apple" |
| 15 | is SampleSealed.B -> "Biscuit" |
| 16 | is SampleSealed.C -> "Cinnamon" |
| 17 | } |
| 18 | |
| 19 | |
| 20 | inline fun SampleSealed.switch(thenA: () -> Unit, thenB: () -> Unit, thenC: () -> Unit) = when (this) { |
| 21 | is SampleSealed.C -> thenC() |
| 22 | is SampleSealed.B -> thenB() |
| 23 | is SampleSealed.A -> thenA() |
| 24 | } |