[libgee] Add Gee.Iterator<G>.foreach method



commit 151512f533345c07a208877dffbcb5c85e5fa463
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Sun Nov 7 22:15:20 2010 +0000

    Add Gee.Iterator<G>.foreach method

 gee/iterator.vala         |    3 ++-
 tests/testcollection.vala |   17 +++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/gee/iterator.vala b/gee/iterator.vala
index 92a7d73..0183c79 100644
--- a/gee/iterator.vala
+++ b/gee/iterator.vala
@@ -25,6 +25,7 @@
 
 namespace Gee {
 	public delegate A FoldFunc<A, G> (G g, owned A a);
+	public delegate void ForallFunc<G> (G g);
 }
 
 /**
@@ -97,7 +98,7 @@ public interface Gee.Iterator<G> : Object {
 	 * Operation moves the iterator to last element in iteration. If iterator
 	 * points at some element it will be included in iteration.
 	 */
-	public virtual void forall (ForallFunc<G> f) {
+	public new virtual void foreach (ForallFunc<G> f) {
 		if (valid)
 			f (get ());
 		while (next ())
diff --git a/tests/testcollection.vala b/tests/testcollection.vala
index 93171cf..f8613c2 100644
--- a/tests/testcollection.vala
+++ b/tests/testcollection.vala
@@ -44,6 +44,7 @@ public abstract class CollectionTests : Gee.TestCase {
 		add_test ("[Collection] to_array", test_to_array);
 		add_test ("[Collection] GObject properties", test_gobject_properties);
 		add_test ("[Collection] fold", test_fold);
+		add_test ("[Collection] foreach", test_foreach);
 	}
 
 	protected Collection<string> test_collection;
@@ -762,4 +763,20 @@ public abstract class CollectionTests : Gee.TestCase {
 		count = iter.fold<int> ((x, y) => {return y + 1;}, 0);
 		assert (count == 3);
 	}
+	
+	public void test_foreach () {
+		assert (test_collection.add ("one"));
+		assert (test_collection.add ("two"));
+		assert (test_collection.add ("three"));
+		
+		int count = 0;
+		
+		test_collection.iterator ().foreach ((x) => {count++;});
+		assert (count == 3);
+		
+		Iterator<string> iter = test_collection.iterator ();
+		assert (iter.next ());
+		iter.foreach ((x) => {count++;});
+		assert (count == 6);
+	}
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]