Skip to content
← Index | Lesson 4 of 5

Enums

Enums (Tagged Unions)

enum Color {
    Red,
    Green,
    Blue,
    Custom(int, int, int),
}

let c = Color.Custom(255, 128, 0)
let name = match c {
    Color.Red          => "Red",
    Color.Green        => "Green",
    Color.Blue         => "Blue",
    Color.Custom(r, g, b) => "RGB({r},{g},{b})",
}
print(name)

Goal: Create an enum Direction with North/South/East/West and a function that returns the opposite.

lesson-4-4.zolo
Program output

Run the code to see the output

Search Zolo

9 results

enespt-br