Skip to content

Instantly share code, notes, and snippets.

@jasononeil
Last active December 19, 2015 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasononeil/5909361 to your computer and use it in GitHub Desktop.
Save jasononeil/5909361 to your computer and use it in GitHub Desktop.
Haxe Abstracts: Array Access with different key types representing different functionality
class ArrayAccessTest {
static function main() {
var myArray:MyArray<Int> = [0,10,20];
trace ( myArray[1] );
trace ( myArray["one"] );
trace ( myArray[["one","two","three"]] );
}
}
abstract MyArray<T>(Array<T>) from Array<T> to Array<T> {
@:arrayAccess public inline function arrayAccessString(key:String)
return key+key;
@:arrayAccess public inline function arrayAccessInt(key:Int):T
return this[key];
@:arrayAccess public inline function arrayAccessArray(key:Array<String>):String
return key.join("-");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment