Overview of Haxe snippets and tutorials tagged with abstract type.
The following EmailAddress Abstract type example is based on the underlying standard String type, but sets the restriction that it can only represent a valid email address. If not, an exception will be thrown.‥
A common pattern, often found in (but not only in) dynamic languages, is to denote the type of some object with a string, for example:‥
The following example demonstrates how a color type can be abstracted over an integer, which stores the color in an ARGB format.‥
This abstract type is based on the underlying Float type, but whenever it is converted back to an actual Float it is rounded to avoid the famous rounding errors occuring in floating point aritmetics.‥
The following Celcius and Fahrenheit Abstract types are based on the underlying Float type, but sets the restriction that it can never hold values below absolute zero. ‥
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.‥