Tutorial by Examples

Haxe's enumeration types are algebraic data types (ADT). Their primary use is for describing data structures. Enums are denoted by the enum keyword and contain one or more enum constructors. enum Color { Red; Green; Blue; RGB(r : Int, g : Int, b : Int); } The above enum can ...
Values passed as enum constructor arguments can be captured into variables by use of pattern matching. Assume the following enum: enum Color { RGB(r : Int, g : Int, b : Int); HSV(h : Int, s : Float, v : Float); } The red channel value can be captured as follows: var color = Color.RG...
Enum constructors can be matched using pattern matching. Assume the following enum: enum Color { Red; Green; Blue; RGB(r : Int, g : Int, b : Int); } Colours with only a green channel value can be matched as follows: var color = Color.RGB(0, 127, 0); var isGreenOnly = swit...

Page 1 of 1