Skip to content

Instantly share code, notes, and snippets.

@xmeta
Created April 8, 2016 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xmeta/70e07b542a7e5d2b9c4c98428b07596e to your computer and use it in GitHub Desktop.
Save xmeta/70e07b542a7e5d2b9c4c98428b07596e to your computer and use it in GitHub Desktop.
sealed class Color {
object Red: Color()
object Green: Color()
object Blue: Color()
class Rgb(val r: Int,val g: Int,val b: Int): Color()
}
fun main(args: Array<String>) {
fun color(c: Color): String = when(c) {
Color.Red -> "#FF0000"
Color.Green -> "#00FF00"
Color.Blue -> "#0000FF"
is Color.Rgb -> "#%02X%02X%02X".format(c.r, c.g, c.b)
}
val color_hex = color(Color.Rgb(255,255, 255))
print("$color_hex")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment