enum
Overview of Haxe code snippets, examples and tutorials tagged with enum.
Jun 16, 2016 Other / Passing different types to a function parameter
Sometimes you find yourself in the need of passing different types to the same parameter of a function. While there isn't a built-in way of doing this in Haxe, thanks to its flexible type system, we can solve this problem. We will explore two ways to achieve this.‥
Dec 14, 2016 Macros / Extract values with pattern matching
Mostly useful to extract enum values from known enum instances. Allows to extract multiple variables at once. Takes most of expressions that are possible to use in switch expression.‥
Mar 25, 2016 Macros / Get all values of an @:enum abstract
The following macro function returns an array of all possible values of a given @:enum abstract type. Since it's not possible in runtime (because abstracts doesn't exist there), we need to use a macro for that.‥
Mar 29, 2016 Macros / Extract values from known enum instances
Sometimes we have an instance of enum that is of known constructor (or we only accept that constructor) and we want to extract values from that instance. Normally, to do this, we have to use pattern matching (switch), however it's quite verbose, so we can instead use this macro static extension method that will generate switch for us.‥
Jan 03, 2017 Functional Programming / Enums as GADTs
As already established Haxe enums are a form of algebraic data types. In fact, they may even serve as so called generalized algebraic data types - GADTs for short. While for an ordinary enum every constructor yields the same type, with an GADT each constructor may yield a different type. ‥
Feb 12, 2018 Functional Programming / ML-Style Parse Tree Evaluation
ML-like languages are great for creating interpreters or compilers, by virtue of Algebraic Data Types. Haxe's enum allow for writing similarly elegant code.‥
Oct 30, 2016 Beginner / Using enum / ADT
Haxe's enumeration types are algebraic data types. Their primary use is for describing data structures.‥
Aug 31, 2017 Beginner / Pattern matching
This article helps to learn pattern matching and all of its type of matching in practice. The article covers basic matching, variable capture, guards, extractors and enum/structure matching.‥