Skip to content

Instantly share code, notes, and snippets.

@tasaquino
Created March 7, 2018 12:06
Show Gist options
  • Save tasaquino/0f8e22814bd0e2c40e7c08c453d2f0b7 to your computer and use it in GitHub Desktop.
Save tasaquino/0f8e22814bd0e2c40e7c08c453d2f0b7 to your computer and use it in GitHub Desktop.
Kotlin - Enum with any object example
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")
}
fun main(args: Array<String>) {
println(mix(Color.YELLOW, Color.BLUE))
// GREEN
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment