Add value-returning match expressions
This commit is contained in:
parent
b0a52de4ea
commit
ab783c33ed
12 changed files with 384 additions and 14 deletions
14
README.md
14
README.md
|
|
@ -108,18 +108,18 @@ enum PaymentResult {
|
|||
}
|
||||
|
||||
fun describe(result: PaymentResult): String {
|
||||
var description = ""
|
||||
match (result) {
|
||||
PaymentResult::Accepted(id) -> { description = id }
|
||||
PaymentResult::Rejected(reason) -> { description = reason }
|
||||
PaymentResult::Pending -> { description = "pending" }
|
||||
return match (result) {
|
||||
PaymentResult::Accepted(id) -> id
|
||||
PaymentResult::Rejected(reason) -> reason
|
||||
PaymentResult::Pending -> "pending"
|
||||
}
|
||||
return description
|
||||
}
|
||||
```
|
||||
|
||||
Enum matches must contain each variant exactly once. Variant payload arity is
|
||||
checked during Gotlin compilation.
|
||||
checked during Gotlin compilation. A match used as an expression also requires
|
||||
every arm to return the same type. Block-style statement matches remain
|
||||
available for side effects.
|
||||
|
||||
## Null safety
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue