Skip to content

Instantly share code, notes, and snippets.

View ReneeVandervelde's full-sized avatar
🌻
Keeping software in full bloom

Renee Vandervelde ReneeVandervelde

🌻
Keeping software in full bloom
View GitHub Profile
View example.kts
val example = when (lightType) {
LightBulb -> ...
LightStrip -> ...
FloodLight -> ...
}
View example.kts
if (myLight == LightType.FloodLight) {
TODO()
}
View example.kts
val example = when (myLight) {
LightBulb -> TODO()
LightStrip -> TODO()
FloodLight -> TODO()
else -> TODO() // This else is *required* now
}
View LightType.kt
enum class LightType {
LightBulb,
LightStrip,
FloodLight,
}
View LightType.kt
value class LightType private constructor(
private val type: String,
) {
companion object {
val LightBulb = LightType("light_bulb")
val LightStrip = LightType("light_strip")
val FloodLight = LightType("flood_light")
}
}
View LightType.kt
value class LightType private constructor(
private val type: String,
) {
companion object {
val LightBulb = LightType("light_bulb")
val LightStrip = LightType("light_strip")
val FloodLight = LightType("flood_light")
fun values() = arrayOf(LightBulb, LightStrip, FloodLight)
}
View LightType.kt
value class LightType private constructor(
private val type: String,
) {
companion object {
val LightBulb = LightType("light_bulb")
val LightStrip = LightType("light_strip")
val FloodLight = LightType("flood_light")
fun values() = arrayOf(LightBulb, LightStrip, FloodLight)
}
View LightType.kt
value class LightType private constructor(
private val type: string,
) {
companion object {
val LightBulb = LightType("light_bulb")
val LightStrip = LightType("light_strip")
val FloodLight = LightType("flood_light")
fun values() = arrayOf(LightBulb, LightStrip, FloodLight)
}
View gist:4805968873b4f1a4084c2aed2369d1e6
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMS
AAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRyb290gAGmCwwXHR4lVSRudWxs1Q0ODxAR
EhMUFRZcTlNDb21wb25lbnRzVU5TUkdCXE5TQ29sb3JTcGFjZV8QEk5TQ3VzdG9tQ29s
b3JTcGFjZVYkY2xhc3NPECcwLjEwNTg4MjM1MjkgMC4xMjE1Njg2Mjc1IDAuMTM3MjU0
@ReneeVandervelde
ReneeVandervelde / UserInfo.kt
Created January 30, 2019 17:34
Simple example of fetching info from an Android SDK class
View UserInfo.kt
class UserInfoFormatter(
private val resources: Resources
) {
fun getDisplayName(user: User) {
if (user.name.isNullOrEmpty()) {
return resources.getString(R.string.name_unknown)
} else {
return user.name
}
}