Created
April 21, 2014 18:22
-
-
Save orangy/11151492 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
| 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