[libgee] Add Gee.Traversable<G> requirement to Gee.Iterable<G>



commit 10549a05cf4183a20041d1a624a20803102571fd
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Fri Jul 22 23:10:06 2011 +0100

    Add Gee.Traversable<G> requirement to Gee.Iterable<G>

 gee/abstractcollection.vala |   10 +++++++++-
 gee/abstractmap.vala        |   16 +++++++++++++++-
 gee/iterable.vala           |    2 +-
 gee/readonlycollection.vala |   16 +++++++++++++++-
 gee/readonlymap.vala        |   16 +++++++++++++++-
 5 files changed, 55 insertions(+), 5 deletions(-)
---
diff --git a/gee/abstractcollection.vala b/gee/abstractcollection.vala
index 8800ba4..ec8f568 100644
--- a/gee/abstractcollection.vala
+++ b/gee/abstractcollection.vala
@@ -30,7 +30,7 @@
  * @see AbstractSet
  * @see AbstractMultiSet
  */
-public abstract class Gee.AbstractCollection<G> : Object, Iterable<G>, Collection<G> {
+public abstract class Gee.AbstractCollection<G> : Object, Traversable<G>, Iterable<G>, Collection<G> {
 
 	/**
 	 * { inheritDoc}
@@ -274,6 +274,14 @@ public abstract class Gee.AbstractCollection<G> : Object, Iterable<G>, Collectio
 	 */
 	public abstract Iterator<G> iterator ();
 
+	public virtual void foreach (ForallFunc<G> f) {
+		iterator ().foreach (f);
+	}
+
+	public virtual Iterator<A> stream<A> (owned StreamFunc<G, A> f) {
+		return iterator ().stream<A> ((owned) f);
+	}
+
 	private weak Collection<G> _read_only_view;
 
 	/**
diff --git a/gee/abstractmap.vala b/gee/abstractmap.vala
index df1acdb..63f5bbd 100644
--- a/gee/abstractmap.vala
+++ b/gee/abstractmap.vala
@@ -29,7 +29,7 @@
  * @see HashMap
  * @see TreeMap
  */
-public abstract class Gee.AbstractMap<K,V> : Object, Iterable<Map.Entry<K,V>>, Map<K,V> {
+public abstract class Gee.AbstractMap<K,V> : Object, Traversable<Map.Entry<K,V>>, Iterable<Map.Entry<K,V>>, Map<K,V> {
 
 	/**
 	 * { inheritDoc}
@@ -207,4 +207,18 @@ public abstract class Gee.AbstractMap<K,V> : Object, Iterable<Map.Entry<K,V>>, M
 	public Iterator<Map.Entry<K,V>> iterator () {
 		return entries.iterator ();
 	}
+
+	/**
+	 * { inheritDoc}
+	 */
+	public virtual void foreach (ForallFunc<Map.Entry<K,V>> f) {
+		iterator ().foreach (f);
+	}
+
+	/**
+	 * { inheritDoc}
+	 */
+	public virtual Iterator<A> stream<A> (owned StreamFunc<Map.Entry<K,V>, A> f) {
+		return iterator ().stream<A> ((owned) f);
+	}
 }
diff --git a/gee/iterable.vala b/gee/iterable.vala
index a6ef612..965bdab 100644
--- a/gee/iterable.vala
+++ b/gee/iterable.vala
@@ -25,7 +25,7 @@ using GLib;
 /**
  * An object that can provide an { link Iterator}.
  */
-public interface Gee.Iterable<G> : Object {
+public interface Gee.Iterable<G> : Object, Traversable<G> {
 	/**
 	 * The type of the elements in this collection.
 	 */
diff --git a/gee/readonlycollection.vala b/gee/readonlycollection.vala
index efaaf84..9b0dc57 100644
--- a/gee/readonlycollection.vala
+++ b/gee/readonlycollection.vala
@@ -31,7 +31,7 @@ using GLib;
  *
  * @see Collection
  */
-internal class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
+internal class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Traversable<G>, Collection<G> {
 
 	/**
 	 * { inheritDoc}
@@ -69,6 +69,20 @@ internal class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
 	/**
 	 * { inheritDoc}
 	 */
+	public void foreach (ForallFunc<G> f) {
+		_collection.foreach (f);
+	}
+
+	/**
+	 * { inheritDoc}
+	 */
+	public Gee.Iterator<A> stream<A> (owned StreamFunc<A> f) {
+		return _collection.stream<A> (f);
+	}
+
+	/**
+	 * { inheritDoc}
+	 */
 	public Type element_type {
 		get { return typeof (G); }
 	}
diff --git a/gee/readonlymap.vala b/gee/readonlymap.vala
index 17e76b5..5be7ff0 100644
--- a/gee/readonlymap.vala
+++ b/gee/readonlymap.vala
@@ -31,7 +31,7 @@ using GLib;
  *
  * @see Map
  */
-internal class Gee.ReadOnlyMap<K,V> : Object, Iterable<Map.Entry<K,V>>, Map<K,V> {
+internal class Gee.ReadOnlyMap<K,V> : Object, Traversable<Map.Entry<K,V>>, Iterable<Map.Entry<K,V>>, Map<K,V> {
 
 	/**
 	 * { inheritDoc}
@@ -222,6 +222,20 @@ internal class Gee.ReadOnlyMap<K,V> : Object, Iterable<Map.Entry<K,V>>, Map<K,V>
 		return entries.iterator ();
 	}
 
+	/**
+	 * { inheritDoc}
+	 */
+	public void foreach (ForallFunc<Map.Entry<K, V>> f) {
+		_map.foreach (f);
+	}
+
+	/**
+	 * { inheritDoc}
+	 */
+	public Iterator<A> stream<A> (owned StreamFunc<Map.Entry<K, V>, A> f) {
+		return _map.stream<A> ((owned) f);
+	}
+
 	protected class MapIterator<K,V> : Object, Gee.MapIterator<K,V> {
 		protected Gee.MapIterator<K,V> _iter;
 



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