HaxeFoundation / haxe.org-comments

Repository to collect comments of our haxe.org websites
2 stars 2 forks source link

[code.haxe.org] Beginner - Using enum / ADT #15

Open utterances-bot opened 5 years ago

utterances-bot commented 5 years ago

Using enum / ADT - Beginner - Haxe programming language cookbook

Haxe's enumeration types are algebraic data types. Their primary use is for describing data structures.

https://code.haxe.org/category/beginner/enum-adt.html

nadako commented 5 years ago

I think it's worth mentioning, that in most of cases you don't have to prefix the constructor name with the type name. If the enum type is imported or known to be the expected type, you can write e.g. Shield directly instead of ItemType.Shield. That will remove some redundant repetitions. I think this is especially useful in pattern matching!

famfubach commented 3 years ago

var enumConstructorNames = ItemType.getNames(); => var enumContructorNames = ItemType.getConstructors();