Skip to content

Instantly share code, notes, and snippets.

@helenwilliamson
Created March 10, 2020 21:26
Show Gist options
  • Save helenwilliamson/55bc6d0b0f442bc305174f7024430d27 to your computer and use it in GitHub Desktop.
Save helenwilliamson/55bc6d0b0f442bc305174f7024430d27 to your computer and use it in GitHub Desktop.
data class Bob(val name: String, val live: Live)
data class Live(val value: Boolean) {
companion object {
fun apply(value: String?): Boolean =
value.let {
if (it.isNullOrBlank()) null else it
}?.toBoolean() ?: false
}
}
val a = Bob("sandwich", Live(true))
Live.apply(null)
Live.apply("")
Live.apply("true")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment