Библиотека реализующая полиморфные функции. Инструкция по установке и использованию:
haxelib install PolymorphFunction
Во FlashDevelop создаем проект, например haXe/Flash:
Заходим Project -> Properies -> Compiler Options -> Libraries
добавляем туда строчку PolymorphFunction
package ;
import flash.Lib;
enum MyEnum {q; w; e;}
class Main
{
static var myfunc:Dynamic = PolymorphFunction.parse([
function(a:Int, b:Int) { return a + b; },
function(a:Int, b:Int, c:Int) { return a + b + c; },
function(value:String) { return "Hello, " + value + "!"; },
function(first:Float, two:String) { return Std.string(first) + " -> " + two; },
function(p1:{ x:Int, y:Int }, p2:{ x:Int, y:Int } ){return { x:p1.x + p2.x, y:p1.y + p2.y };},
function(arr:Array<Dynamic>) { return "This is Array<Dynamic>"; },
function(arr:Array<Int>) { return "This is Array<Int>"; },
function(arr:Array<{x:Int}>) { return "This is Array<{Int}>"; },
function(a:MyEnum) { return "This is MyEnum"; },
]);
static function main()
{
trace(myfunc(10,20)); //30
trace(myfunc(1,2,3)); //6
trace(myfunc("Mr.Cheater")); //Hello, Mr.Cheater!
trace(myfunc(1.5, "DOG")); //CAT -> DOG
trace(myfunc( { x:10, y:20 }, { x:5, y: -10 } )); //{x:15, y:10}
trace(myfunc( [[10, 20], 30] )); //This is Array<Dynamic>
trace(myfunc( [10, 20, 30] )); //This is Array<Int>
trace(myfunc( [{x:10}, {x:20}, {x:30}] )); //This is Array<{Int}>
trace(myfunc( MyEnum.q )); //This is MyEnum
}
}