blob: 5cd80b5d8d26b05ed53fecc15059de4e0bee991d [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
Vsevolod Tolstopyatov74bcc922018-05-03 20:07:54 +03005package cases.whenMappings
6
7sealed class SampleSealed {
8 class A : SampleSealed()
9 class B : SampleSealed()
10 class C : SampleSealed()
11}
12
13fun SampleSealed.deacronimize() = when (this) {
14 is SampleSealed.A -> "Apple"
15 is SampleSealed.B -> "Biscuit"
16 is SampleSealed.C -> "Cinnamon"
17}
18
19
20inline 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}