Haxe Code Cookbook

pattern matching

Overview of Haxe code snippets, examples and tutorials tagged with pattern matching.

  • Jan 23, 2018 Beginner /

     enum pattern-matching data-structures

    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.‥

  • Jan 23, 2018 Functional Programming /

     enum pattern-matching functional-programming

    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. ‥

  • Jan 23, 2018 Macros /

     enum pattern-matching expression-macro

    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 23, 2018 Other /

     enum abstract-type pattern-matching type-parameter type-parameter-constraint

    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.‥