lib/standard: introduce *Iterator::finish
authorJean Privat <jean@pryen.org>
Thu, 9 Oct 2014 00:29:21 +0000 (20:29 -0400)
committerJean Privat <jean@pryen.org>
Thu, 9 Oct 2014 00:29:21 +0000 (20:29 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/collection/abstract_collection.nit

index d2cdb2c..843f8eb 100644 (file)
@@ -152,6 +152,16 @@ interface Iterator[E]
 
        # Iterate over `self`
        fun iterator: Iterator[E] do return self
+
+       # Post-iteration hook.
+       #
+       # Used to inform `self` that the iteration is over.
+       # Specific iterators can use this to free some resources.
+       #
+       # Is automatically invoked at the end of `for` structures.
+       #
+       # Do nothing by default.
+       fun finish do end
 end
 
 # A collection that contains only one item.
@@ -526,6 +536,16 @@ interface MapIterator[K: Object, V]
 
        # Set a new `item` at `key`.
        #fun item=(item: E) is abstract
+
+       # Post-iteration hook.
+       #
+       # Used to inform `self` that the iteration is over.
+       # Specific iterators can use this to free some resources.
+       #
+       # Is automatically invoked at the end of `for` structures.
+       #
+       # Do nothing by default.
+       fun finish do end
 end
 
 # Iterator on a 'keys' point of view of a map