Last active
December 19, 2015 06:09
-
-
Save jasononeil/5909361 to your computer and use it in GitHub Desktop.
Haxe Abstracts: Array Access with different key types representing different functionality
This file contains hidden or 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 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