Skip to main content

Enums

An enum describes a fixed set of related names. A value of the enum is always exactly one of them:

enum Direction { North, East, South, West }

let heading = Direction.North

In V0 a case is a bare name and carries no data.

Comparing cases​

=== tests whether two values are the same case:

enum Direction { North, East, South, West }

let heading = Direction.North
let goingNorth = heading === Direction.North

Branching on a case​

match is the idiomatic way to branch on which case you have, and match! makes the compiler check that every case is handled:

enum People { Teacher, Student, Unnamed }

let describe(person: People) = match!(person) {
People.Teacher -> "a teacher"
People.Student -> "a student"
People.Unnamed -> "someone"
}