Skip to content

Instantly share code, notes, and snippets.

@dpeek
Created October 21, 2013 11:17
Show Gist options
  • Select an option

  • Save dpeek/7082237 to your computer and use it in GitHub Desktop.

Select an option

Save dpeek/7082237 to your computer and use it in GitHub Desktop.
import haxe.macro.Expr;
class Func
{
public static function each<T>(it:Iterable<T>, cb:T -> Void)
{
for (i in it) cb(i);
}
public static function every<T>(it:Iterable<T>, cb:T -> Bool):Bool
{
for (i in it) if (!cb(i)) return false;
return true;
}
public static function and<T>(it:Iterable<T -> Bool>):T -> Bool
{
return function (e:T) return every(it, function(i) return i(e));
}
macro public static function pluck<A, B>(it:ExprOf<Iterable<A>>, field:String):ExprOf<Iterable<B>>
{
return macro Lambda.map($it, function(i) return i.$field);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment