|
@@ -50,8 +50,40 @@ class List<T> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function remove( v : T ) : Bool {
|
|
|
+ var loop;
|
|
|
+ var found = { ref : false };
|
|
|
+ loop = function(h) {
|
|
|
+ return switch h {
|
|
|
+ case empty:
|
|
|
+ empty;
|
|
|
+ case cons(v2,h):
|
|
|
+ if( v2 == v ) {
|
|
|
+ found.ref = true;
|
|
|
+ h;
|
|
|
+ } else
|
|
|
+ cons(v2,loop(h));
|
|
|
+ }
|
|
|
+ };
|
|
|
+ h = loop(h);
|
|
|
+ return found.ref;
|
|
|
+ }
|
|
|
+
|
|
|
public function iterator() : Iterator<T> {
|
|
|
return new ListIter<T>(h);
|
|
|
}
|
|
|
|
|
|
+ public function toString() {
|
|
|
+ var s = new StringBuf();
|
|
|
+ var it = iterator();
|
|
|
+ s.add("{");
|
|
|
+ for i in it {
|
|
|
+ s.add(i);
|
|
|
+ if( it.hasNext() )
|
|
|
+ s.add(", ");
|
|
|
+ }
|
|
|
+ s.add("}");
|
|
|
+ return s.toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|