Browse Source

added Array iterators.

Nicolas Cannasse 19 years ago
parent
commit
a338aad6ee
2 changed files with 27 additions and 1 deletions
  1. 2 0
      std/Array.hx
  2. 25 1
      std/flash/Boot.hx

+ 2 - 0
std/Array.hx

@@ -22,5 +22,7 @@ extern class Array<T> {
 	function insert( pos : Int, x : T ) : Void;
 	function remove( x : T ) : Bool;
 	function copy() : Array<T>;
+	function iterator() : Iterator<T>;
+	function indexes() : Iterator<Int>;
 
 }

+ 25 - 1
std/flash/Boot.hx

@@ -30,7 +30,6 @@ class Boot {
 			flash.system.IME._UNKNOWN = System["IME"]["UNKNOWN"];
 			#end
 
-			String.prototype.sub = String.prototype.substr;
 			Array.prototype.copy = Array.prototype.slice;
 			Array.prototype.insert = function(i,x) {
 				this.splice(i,0,x);
@@ -47,6 +46,31 @@ class Boot {
 				}
 				return false;
 			}
+			Array.prototype.iterator = function() {
+				return {
+					cur : 0,
+					max : this.length,
+					arr : this,
+					hasNext : function() {
+						return this.cur < this.max;
+					},
+					next : function() {
+						return this.arr[this.cur++];
+					}
+				}
+			};
+			Array.prototype.indexes = function() {
+				return {
+					cur : 0,
+					max : this.length,
+					hasNext : function() {
+						return this.cur < this.max;
+					},
+					next : function() {
+						return this.cur++;
+					}
+				}
+			};
 		}
 	}