Browse Source

added Iterator.

Nicolas Cannasse 19 years ago
parent
commit
00dbe33751
3 changed files with 29 additions and 0 deletions
  1. 21 0
      std/IntIter.hx
  2. 6 0
      std/Iterator.hx
  3. 2 0
      std/haxe/ImportAll.hx

+ 21 - 0
std/IntIter.hx

@@ -0,0 +1,21 @@
+class IntIter implements Iterator<Int> {
+
+	var min : Int;
+	var max : Int;
+
+	public function new( min : Int, max : Int ) {
+		this.min = min;
+		this.max = max;
+	}
+
+	public function hasNext() {
+		return min != max;
+	}
+
+	public function next() {
+		if( min < max )
+			return min++;
+		return min--;
+	}
+
+}

+ 6 - 0
std/Iterator.hx

@@ -0,0 +1,6 @@
+interface Iterator<T> {
+
+	function hasNext() : Bool;
+	function next() : T;
+
+}

+ 2 - 0
std/haxe/ImportAll.hx

@@ -2,6 +2,8 @@
 import Array;
 import Date;
 import ImportAll;
+import IntIter;
+import Iterator;
 import List;
 import Math;
 import Std;