Skip to content

Instantly share code, notes, and snippets.

@orangy
Created April 21, 2014 18:22
Show Gist options
  • Select an option

  • Save orangy/11151492 to your computer and use it in GitHub Desktop.

Select an option

Save orangy/11151492 to your computer and use it in GitHub Desktop.
data class IBAN(val country: String, val account : String)
// parseIBAN returns nullable IBAN
fun parseIBAN(code : String) : IBAN? {
...
}
val iban = parseIBAN(userInput)
when (iban) {
null -> throw InvalidIBANException()
else -> when(iban.country) { // iban here is already of type IBAN, not nullable
"DE" -> ...
"IT" -> ...
else -> ... all other countries
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment