Created
March 7, 2018 14:23
-
-
Save tasaquino/36df97f8b34071265582badc4b3705af to your computer and use it in GitHub Desktop.
Kotlin - When conditions with blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun printAnimalsOf(house: House) = | |
when (house) { | |
is Stark -> { | |
val wolves = house.wolves() | |
println(wolves) | |
} | |
is Targeryen -> { | |
val dragons = house.daenerysDragons() | |
println(dragons) | |
} | |
else -> throw IllegalArgumentException("Unknown house") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment