Created
April 8, 2016 08:31
-
-
Save xmeta/70e07b542a7e5d2b9c4c98428b07596e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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