Skip to content

Instantly share code, notes, and snippets.

@nadako
Created May 5, 2014 23:15
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 nadako/64addeb08e4a87907dbf to your computer and use it in GitHub Desktop.
Save nadako/64addeb08e4a87907dbf to your computer and use it in GitHub Desktop.
import Reverse.reverse;
class Main
{
static function main()
{
var a = [1,2,3];
for (v in reverse(a))
{
trace(v);
}
}
}
Main.main = function() {
var a = [1,2,3];
var _g_array = a;
var _g_length = a.length;
while(_g_length > 0) {
var v = _g_array[--_g_length];
console.log(v);
}
};
class Reverse<T>
{
var array:Array<T>;
var length:Int;
inline function new(array:Array<T>)
{
this.array = array;
this.length = array.length;
}
public inline function hasNext():Bool
{
return length > 0;
}
public inline function next():T
{
return array[--length];
}
public static inline function reverse<T>(array:Array<T>):Reverse<T>
{
return new Reverse(array);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment