Splitter Test written. Doesn't pass.
[order_line_extra.git] / haxe / QueryIterator.hx
1 enum Maybe<T> {
2         Nothing;
3         Just(v : T);
4 }
5
6 class QueryIterator<T> {
7         var result : Dynamic;
8         var nextValue : Maybe<T>;
9         public function new(result) {
10                 this.result= result;
11                 /* We fetch the first row , so we can answer hasNext */
12                 fetch();
13         }
14
15         private function fetch() {
16                 var next : Dynamic = untyped __call__('db_fetch', this.result);
17                 nextValue = if(next) Just(next) else Nothing;
18         }
19
20         public function  hasNext() : Bool {
21                 return this.nextValue != Nothing;
22         }
23
24         public function next() : T {
25                 switch(this.nextValue) {
26                 case Nothing : throw 'Iterator exhausted';
27                 case Just(v) :  {
28                         this.fetch();
29                         return v;
30                 };
31                 }
32         }
33 }