abstract type
Overview of Haxe code snippets, examples and tutorials tagged with abstract type.
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.‥
Oct 13, 2016 Abstract types / Color as abstract type
The following example demonstrates how a color type can be abstracted over an integer, which stores the color in an ARGB format.‥
Apr 19, 2016 Abstract types / Temperature units as abstract type
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. ‥
Mar 03, 2021 Abstract types / Pipe using Abstract Operator Overloading
The following example demonstrates how the pipe operator is used to clean up nested function calls with Abstract Operator Overloading.‥
Aug 16, 2016 Abstract types / Strict typing for stringly-typed extern code
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:‥
Nov 21, 2017 Abstract types / Using Iterators as Generic Type Parameters
Iterators are a helpful Haxe structure. Any structure that implements the next and hasNext functions with the appropriate signature will allow you build a for loop. Arrays have an iterator() function that returns exactly this, and you don't need to call it, the for language construction does it for you.‥
Apr 13, 2016 Abstract types / Email address as 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.‥
Apr 20, 2016 Abstract types / Rounded Float as abstract type
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.‥
Nov 21, 2017 Abstract types / Array access of a database manager
When using SPOD database objects, or the record-macros library, instances of database models can be accessed using the manager's get function:‥