Created
April 6, 2015 11:13
-
-
Save nadako/3db9c067a4e93d64d1f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Tools; | |
class Main { | |
static function main() { | |
var a = haxe.ds.Option.Some(42); | |
var s = a.extract(Some(v) => {value: v}); | |
trace(s); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
new url for @boozook comment https://gist.github.com/boozook/9d27b0011734bb8e33e5#file-tools-hx-L12-L13