Add value-returning match expressions
This commit is contained in:
parent
b0a52de4ea
commit
ab783c33ed
12 changed files with 384 additions and 14 deletions
|
|
@ -7,13 +7,11 @@ enum PaymentResult {
|
|||
}
|
||||
|
||||
fun describe(result: PaymentResult): String {
|
||||
var description = ""
|
||||
match (result) {
|
||||
PaymentResult::Accepted(id) -> { description = "accepted " + id }
|
||||
PaymentResult::Rejected(reason) -> { description = "rejected " + reason }
|
||||
PaymentResult::Pending -> { description = "pending" }
|
||||
return match (result) {
|
||||
PaymentResult::Accepted(id) -> "accepted " + id
|
||||
PaymentResult::Rejected(reason) -> "rejected " + reason
|
||||
PaymentResult::Pending -> "pending"
|
||||
}
|
||||
return description
|
||||
}
|
||||
|
||||
fun main() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue