This is a small post about a small, useful macro for Haxe.
As you may (or may not) know, Haxe has fancy enums (which are actually algebraic data types). That's nice. And you can do all sorts of fancy value matching on them, which is also nice.
What is less nice, however, is that the only conventional way to extract enum arguments is to "match" it, and thus in some situations you can only do code like this,
var r = switch (expr) { case one(k): k; default: -1; };
adding a couple lines of code in place of what feels like it could have been a single operator.
So I wrote a tiny macro which adds just that:
var r = ematch(expr, some(k), k, -1);Continue reading