Skip to content

Instantly share code, notes, and snippets.

@tasaquino
Created March 7, 2018 14:23
Show Gist options
  • Save tasaquino/36df97f8b34071265582badc4b3705af to your computer and use it in GitHub Desktop.
Save tasaquino/36df97f8b34071265582badc4b3705af to your computer and use it in GitHub Desktop.
Kotlin - When conditions with blocks
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