Skip to content

Instantly share code, notes, and snippets.

@Simn
Created November 3, 2012 16:59
Show Gist options
  • Save Simn/4007900 to your computer and use it in GitHub Desktop.
Save Simn/4007900 to your computer and use it in GitHub Desktop.
Function-based specialization wizardry in haxe3
class Main {
static function main() {
trace(process(12)); // 24
trace(process("Hello world")); // HELLO WORLD
}
@:generic static function process<T>(t:T):T {
return throw "unknown type: " + t;
}
static function process_Int(t:Int) {
trace("I'm an integer.");
return t * 2;
}
static function process_String(t:String) {
trace("I'm a string.");
return t.toUpperCase();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment