Add value-returning match expressions

This commit is contained in:
pavel 2026-08-27 17:56:13 +02:00
commit ab783c33ed
12 changed files with 384 additions and 14 deletions

View file

@ -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() {