lib/core/collection: add start so iterators are usable with `with`
authorJean Privat <jean@pryen.org>
Thu, 24 Sep 2015 17:18:56 +0000 (13:18 -0400)
committerJean Privat <jean@pryen.org>
Thu, 24 Sep 2015 17:18:56 +0000 (13:18 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/core/collection/abstract_collection.nit

index 5192797..aca4fdc 100644 (file)
@@ -228,6 +228,16 @@ interface Iterator[E]
        # Iterate over `self`
        fun iterator: Iterator[E] do return self
 
+       # Pre-iteration hook.
+       #
+       # Used to inform `self` that the iteration is starting.
+       # Specific iterators can use this to prepare some resources.
+       #
+       # Is automatically invoked at the beginning of `for` structures.
+       #
+       # Do nothing by default.
+       fun start do end
+
        # Post-iteration hook.
        #
        # Used to inform `self` that the iteration is over.
@@ -708,6 +718,16 @@ interface MapIterator[K, V]
        # Set a new `item` at `key`.
        #fun item=(item: E) is abstract
 
+       # Pre-iteration hook.
+       #
+       # Used to inform `self` that the iteration is starting.
+       # Specific iterators can use this to prepare some resources.
+       #
+       # Is automatically invoked at the beginning of `for` structures.
+       #
+       # Do nothing by default.
+       fun start do end
+
        # Post-iteration hook.
        #
        # Used to inform `self` that the iteration is over.