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
enum class House { | |
BARATHEON, | |
BOLTON, | |
LANNISTER, | |
MARTELL, | |
REDWYNE, | |
STARK, | |
TARGARYEN, | |
TULLY; | |
} |
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
enum class House(val words:String) { | |
BARATHEON("Ours Is the Fury"), | |
BOLTON("Our Blades Are Sharp"), | |
LANNISTER("A Lannister Always Pays His Debts"), | |
MARTELL("Unbowed, Unbent, Unbroken"), | |
STARK("Winter Is Coming"), | |
TARGARYEN("Fire and Blood"), | |
TULLY("Family, Duty, Honor"); | |
} |
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
enum class House(val words:String) { | |
BARATHEON("Ours Is the Fury"), | |
BOLTON("Our Blades Are Sharp"), | |
LANNISTER("A Lannister Always Pays His Debts"), | |
MARTELL("Unbowed, Unbent, Unbroken"), | |
STARK("Winter Is Coming"), | |
TARGARYEN("Fire and Blood"), | |
TULLY("Family, Duty, Honor"); | |
fun sayWords() = "Words: $words" |
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
interface SaySomething { | |
fun say(): String | |
} | |
enum class House : SaySomething { | |
BARATHEON { | |
override fun say() = "Ours Is the Fury" | |
}, | |
BOLTON { | |
override fun say() = "Our Blades Are Sharp" |
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 showWordsOfHouse(house: House) = | |
when (house) { | |
House.BARATHEON -> "Ours Is the Fury" | |
House.BOLTON -> "Our Blades Are Sharp" | |
House.LANNISTER -> "A Lannister Always Pays His Debts" | |
House.MARTELL -> "Unbowed, Unbent, Unbroken" | |
House.STARK -> "Winter Is Coming" | |
House.TARGARYEN -> "Fire and Blood" | |
House.TULLY -> "Family, Duty, Honor" | |
} |
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 showIsGreatHouse(house: House) = | |
when (house) { | |
House.TARGARYEN, House.LANNISTER, House.STARK -> "$house is a great house" | |
else -> "bla" | |
} | |
fun main(args: Array<String>) { | |
println(showIsGreatHouse(House.LANNISTER)) | |
// LANNISTER is a great house | |
} |
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
enum class Color { | |
RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET | |
} | |
fun mix(firstColor: Color, secondColor: Color) = | |
when (setOf(firstColor, secondColor)) { | |
setOf(Color.RED, Color.YELLOW) -> Color.ORANGE | |
setOf(Color.YELLOW, Color.BLUE) -> Color.GREEN | |
setOf(Color.BLUE, Color.VIOLET) -> Color.INDIGO | |
else -> throw Exception("bla color") |
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
interface House | |
class Stark : House{ | |
fun wolves() = arrayListOf("Ghost", "Grey Wind", "Summer", "Lady", "ShaggyDog", "Nymeria") | |
} | |
class Targeryen : House{ | |
fun daenerysDragons() = arrayListOf("Drogon", "Viserion", "Rhaegal") | |
} |
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) | |
} |
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
val person: Person = attributes.let { | |
mapToPerson(it.first, it.second) | |
} |
OlderNewer