Enums
the main difference between enums and unions is that a root qualifier is required for their instantiation
enum Color = RED | BLUE | GREEN
color = Color.RED
With fields
You can add custom fields to the root of enums, and set its value in each branch.
enum Color r: Int g: Int b: Int =
| RED r: 255 g: 0 b: 0
| GREEN r: 0 g: 255 b: 0
| PURPLE r: 128 g: 0 b: 128
rg = Color.RED r + Color.GREEN g
rg echo
Messages
In niva everything is object, and you can declare and send messages to them, so enums are no different
Color sumOfColors = r + g + b
Color.PURPLE sumOfColors echo
Last modified: 22 October 2024