Skip to content

Instantly share code, notes, and snippets.

View devboy's full-sized avatar

Dominic Graefen devboy

View GitHub Profile
var circle = { x: 10, y: 10, radius: 10 };
var rect = { x: 20, y: 20, width: 100, height: 100 };
function move( objectWithXAndY: { x: Int, y: Int } )
{
objectWithXAndY.x += 5;
objectWithXAndY.y += 5;
}
// both calls will work
var circle: { x: Int, y: Int, radius: Int };
circle = {x: 10, y: 10, radius: 10};
var circle = { x: 100, y: 100, radius: 50 }
circle.x = 90; // will work fine
circle.y = "100"; // error: String should be Int
circle = { x: 90, y: 80, radius: 10 } // will work fine
circle = "circle"; // error: String should be { y : Int, x : Int, radius : Int }
var circle = { x: 100, y: 100, radius: 50 };
type(circle); // returns { y : Int, x : Int, radius : Int }
package org.devboy;
import haxe.macro.Type;
import neko.Lib;
import haxe.macro.Expr;
import haxe.macro.Context;
class Funk
{
@:macro public static function partial( expressions: Array<Expr> ): Expr
function multiply( x: Float, y: Float ): Float
{
return x * y;
}
// now we create a partial function, with a preset parameters
var multiplyByTen = Funk.partial( multiply, 10 );
// now we can call multiplyByTen to multiply a number by ten
package org.devboy;
import haxe.macro.Type;
import neko.Lib;
import haxe.macro.Expr;
import haxe.macro.Context;
class Funk
{
5.times( callback( trace, "Hello" ) ) //traces Hello 5 times
5.times( callback( trace, "Hello" ) ) //traces Hello 5 times
import org.devboy.ArrayUtils;
using org.devboy.ArrayUtils;
type( ArrayUtils.delete_if ); // Array<T> -> (T -> Bool) -> Array<T>
type( [].delete_if ); // (T -> Bool) -> Array<T>