The first switch case matches when the train’s status is OnTime, and returns a simple string message.

The second switch case is more complex. It starts by using the combined pattern let .Delayed(minutes) to match a Status enumeration case of Delayed and bind its associated integer value to a temporary constant called minutes. This pattern enables you to use the minutes constant inside the switch case’s code block to access the associated number of minutes if the pattern is matched.

This switch case also adds a guard expression (indicated by the where keyword), which restricts the situations in which the case will be matched. Here, the guard expression matches only when the extracted value of minutes is in the range 0...5. This restriction is enforced with the pattern-match (~=) operator.

The third and final switch case matches all remaining Delayed cases.

You can now create a few Train instances and set some of them to be delayed.