Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nadako
Created April 6, 2015 11:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nadako/3db9c067a4e93d64d1f4 to your computer and use it in GitHub Desktop.
Save nadako/3db9c067a4e93d64d1f4 to your computer and use it in GitHub Desktop.
using Tools;
class Main {
static function main() {
var a = haxe.ds.Option.Some(42);
var s = a.extract(Some(v) => {value: v});
trace(s);
}
}
class Tools {
public static macro function extract(value:haxe.macro.Expr.ExprOf<EnumValue>, pattern:haxe.macro.Expr) {
return switch (pattern) {
case macro $a => $b:
macro switch ($value) {
case $a:
$b;
default:
throw "no match";
}
default:
throw new haxe.macro.Expr.Error("Invalid enum value extraction pattern", pattern.pos);
}
}
}
@boozook
Copy link

boozook commented Apr 6, 2015

Little improvement: see my fork.

@bayleedev
Copy link

@boozook
Copy link

boozook commented Nov 3, 2022

@bayleedev Thank you! 🙏
But i'm not sure how it useful and actual today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment