Created
November 3, 2012 16:59
-
-
Save Simn/4007900 to your computer and use it in GitHub Desktop.
Function-based specialization wizardry in haxe3
This file contains 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 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