Skip to content

Instantly share code, notes, and snippets.

@francescoagati
francescoagati / macros.hx
Created October 5, 2015 01:27
abstract operators and macros haxe
import haxe.macro.Expr;
class Macros {
public static macro function map(expr:Expr) {
return macro function(_) {
return $expr;
}
}
var x = 1,y = 1;
sure (x == y, x==1);
//or
sure({
x==1;
y==2; //throw an error
});
var x = 1,y =1;
asserTrue(x,y);
return switch e {
case macro [$a{lefts}] = [$a{rights}]: processArrays(lefts,rights);
case macro [$a{lefts}] << ${right}: processObject(lefts,right);
case _:e.map(processDestructuring);
}
import haxe.macro.Expr;
using haxe.macro.ExprTools;
using haxe.macro.MacroStringTools;
class Let {
static function processDestructuring(e:Expr) {
inline function processArrays(lefts:Array<Expr>,rights) {
var x = 1;
var y = 2;
var z = 3;
var person = { name : "mario", surname : "rossi", age : 25};
console.log(person);
var name = person.name;
var surname = person.surname;
var a = x;
var b = y;
var c = z;
var x = 1;
var y = 2;
var z = 3;
var list = [1,2,3];
var person = {name:'mario',surname:'rossi',age:25};
trace(person);
let({
[name,surname] << person;
[a,b,c] = [x,y,z];
let({
[name,surname] << person;
[a,b,c] = [x,y,z];
});
@francescoagati
francescoagati / ad.ls
Created June 7, 2015 21:34
assignment destructuing haxe
[x,y,z] = [1,2,3]
[name,surname] = person
import Slambda.fn;
fn(_ + 1);
fn(x => x + 1);