Skip to content

Instantly share code, notes, and snippets.

//implicit parameters
// use _ for unary functions or _1 _2 _3 for multiple arguments functions
fn(_ + 1);
fn(_1 + _2);
//explicit parameters
// use x => for single argument
// and [x,y,z] => for multiple arguments
fn(x => x + 1);
[1,2,3,4,5].filter.fn( _ >= 3 ).map.fn( _ + 1)
@francescoagati
francescoagati / Main.hx
Created June 7, 2015 20:23
access dynamic objects in haxe usgin macro haxe
using Path;
class Main {
public static function main() {
var w:Dynamic = untyped dynamic_object;
w.path(_.a.bc.d.e.f.g.h);
w.path(_.a.bc.d.e.f.g.h = 2);
}
}
using riot.RiotTools;
@:keep
class BaseComponent implements riot.IRiotComponent {
public var view:Dynamic;
@:bind function incr() {
js.Lib.debug();
view.counter++;
}
@:tagName('component-inheritance-2')
@:template('
component inheritance 2
<button onclick={incr}>incr</button>
<button onclick={async_incr}>async incr</button>
<span class="counter2">{counter}</span>
')
@:css('
.counter2 {
background:yellow;
@francescoagati
francescoagati / riot.hx
Last active August 29, 2015 14:22
riot.hx
using riot.RiotTools;
@:tagName('counter')
@:templateFile('templates/counter/counter.html')
@:cssFile('templates/counter/counter.css')
@:autoMount
@:keep
class Component implements riot.IRiotComponent {
public var view:Dynamic;
@francescoagati
francescoagati / Main.hx
Created June 6, 2015 15:53
using haxe web dispatcher with flask and python target
import haxe.Constraints.Function;
import python.KwArgs;
using python.Lib;
@:pythonImport("flask", "request")
extern class Request implements Dynamic {
public static var args:python.Dict<String,Dynamic>;
}
@francescoagati
francescoagati / Cond.hx
Last active August 29, 2015 14:22
condition forms lisp inspired in haxe
import haxe.macro.Context;
import haxe.macro.Expr;
using haxe.macro.ExprTools;
using haxe.macro.MacroStringTools;
class Cond {
static function processDSL(e:Expr) {
return switch e {
@francescoagati
francescoagati / Dsl.hx
Created June 3, 2015 01:30
exploring pattern matching in macro haxe
import haxe.macro.Expr;
using haxe.macro.ExprTools;
using haxe.macro.MacroStringTools;
class Dsl {
static function processDSL(e:Expr) {
return switch e {
case macro @select $i{select}: {
macro 'you say select ${select}';
@francescoagati
francescoagati / main.class.php
Last active August 29, 2015 14:22
write performant php code with haxe abstractions like macro, static extensions and types. Example with Slim3
<?php
class Main {
public function __construct(){}
static function newSlimApp() {
return _hx_anonymous(array("app" => new \Slim\App()));
}
static function main() {
$slim = _hx_anonymous(array("app" => new \Slim\App()));
{