Add Gee.Traversable<G> requirement to Gee.Iterable<G>
authorMaciej Piechotka <uzytkownik2@gmail.com>
Fri, 22 Jul 2011 22:10:06 +0000 (23:10 +0100)
committerMaciej Piechotka <uzytkownik2@gmail.com>
Fri, 22 Jul 2011 22:10:06 +0000 (23:10 +0100)
gee/abstractcollection.vala
gee/abstractmap.vala
gee/iterable.vala
gee/readonlycollection.vala
gee/readonlymap.vala

index 8800ba4..ec8f568 100644 (file)
@@ -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;
 
        /**
index df1acdb..63f5bbd 100644 (file)
@@ -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);
+       }
 }
index a6ef612..965bdab 100644 (file)
@@ -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.
         */
index efaaf84..9b0dc57 100644 (file)
@@ -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); }
        }
index 17e76b5..5be7ff0 100644 (file)
@@ -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;