Created
June 16, 2016 16:32
-
-
Save francescoagati/7a9208008202aefd7f725fabb72393f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Getter<T> { | |
var filter:String; | |
var obj:Array<T>; | |
public inline function new(obj:Array<T>,filter:String) { | |
this.filter = filter; | |
this.obj = obj; | |
} | |
public inline function get(value:Dynamic) { | |
var new_list:Array<T> = []; | |
for (element in obj) { | |
var dyn:haxe.DynamicAccess<T> = untyped element; | |
if (dyn[filter] == value) new_list.push(element); | |
}; | |
return new_list; | |
} | |
} | |
abstract Resolver<T>(Array<T>) from Array<T> to Array<T> { | |
@:resolve public inline function resolver(filter:String) { | |
return new Getter(this,filter); | |
} | |
} | |
typedef Player = { | |
name:String, | |
surname:String | |
} | |
class Test { | |
static function main() { | |
var wrapper:Resolver<Player> = [ | |
{name:'mario',surname:'rossi'}, | |
{name:'paolo',surname:'bianchi'}, | |
]; | |
trace(wrapper.name.get('mario')[0].name); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by Haxe 3.3.0 | |
(function () { "use strict"; | |
var Test = function() { }; | |
Test.main = function() { | |
var wrapper = [{ name : "mario", surname : "rossi"},{ name : "paolo", surname : "bianchi"}]; | |
var _this_obj = wrapper; | |
var new_list = []; | |
var _g = 0; | |
while(_g < _this_obj.length) { | |
var element = _this_obj[_g]; | |
++_g; | |
if(element.name == "mario") { | |
new_list.push(element); | |
} | |
} | |
console.log(new_list[0].name); | |
}; | |
Test.main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment