# polymorphfunction

Polymorphic functions. Library. Version 1.0

The library implements a polymorphic function. Instructions for installation and use:

haxelib install PolymorphFunction

In FlashDevelop create a project, for example Haxe / Flash:

Go Project -> Properies -> Compiler Options -> Libraries

```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
}
}```
version #10208, modified 2011-02-20 13:25:34 by MrCheater