Enumerated Type

Examples Filter
// The iota keyword represents successive integer constants 0, 1, 2,…
// It resets to 0 whenever the word const appears in the source code,
// and increments after each const specification.
const (
	C0 = iota
	C1
	C2
)
fmt.Println(C0, C1, C2) // "0 1 2"

// To start a list of constants at 1 instead of 0, you can use iota in an arithmetic expression.
const (
    C1 = iota + 1
    C2
    C3
)
fmt.Println(C1, C2, C3) // "1 2 3"

const (
    C1 = iota + 1
    _
    C3
    C4
)
fmt.Println(C1, C3, C4) // "1 3 4"

// Complete enum type with strings [best practice]
type Direction int
const (
    North Direction = iota
    East
    South
    West
)
func (d Direction) String() string {
    return [...]string{"North", "East", "South", "West"}[d]
}
enum Color {
	red green blue
}

mut color := Color.red
// V knows that `color` is a `Color`. No need to use `color = Color.green` here.
color = .green
println(color) // "1"  TODO: print "green"?