Skip to content

Match

Syntax

decide(<Command>, <State>) {
match <expression> {
<pattern> -> [<Event>, ...]
<pattern> -> [<Event>, ...]
_ -> [<Event>, ...]
}
}

Match blocks enable conditional event emission based on runtime values. They appear inside decide block bodies as an alternative to a direct emission statement.

Match Arms

Each arm has a pattern and an emission list. Arms are evaluated top-to-bottom.

Wildcard

The _ pattern matches any value. It typically appears as the last arm to ensure exhaustive coverage.

With Guards and Postconditions

Match blocks can be combined with require guards and ensure postconditions:

decide(UpdateStatus, Active) {
require status != old.status
else reject "Status unchanged"
match status {
"approved" -> [StatusApproved]
"rejected" -> [StatusRejected]
_ -> [StatusUpdated { newStatus: status }]
}
ensure currentStatus != old.currentStatus
}

Example

decide(SetPriority, Open) {
match priority {
1 -> [PrioritySetCritical]
2 -> [PrioritySetHigh]
_ -> [PrioritySetNormal { level: priority }]
}
}