package haxe; import php.*; import haxe.iterators.RestIterator; import haxe.iterators.RestKeyValueIterator; private typedef NativeRest = NativeIndexedArray; @:coreApi @:semantics(value) abstract Rest(NativeRest) { public var length(get,never):Int; inline function get_length():Int return Global.count(this); @:from static public inline function of(array:Array):Rest return new Rest(@:privateAccess array.arr); inline function new(a:NativeIndexedArray):Void this = a; @:arrayAccess inline function get(index:Int):T return this[index]; @:to public inline function toArray():Array return @:privateAccess Array.wrap(this); public inline function iterator():RestIterator return new RestIterator(this); public inline function keyValueIterator():RestKeyValueIterator return new RestKeyValueIterator(this); public inline function append(item:T):Rest { var result = this; result.push(item); return new Rest(result); } public inline function prepend(item:T):Rest { var result = this; Global.array_unshift(result, item); return new Rest(result); } public function toString():String { return inline Boot.stringifyNativeIndexedArray(this); } }