Merge: lib/string: some cleaning, doc and unit tests
[nit.git] / lib / standard / collection / array.nit
index f6511be..6fe304e 100644 (file)
@@ -131,6 +131,7 @@ abstract class AbstractArrayRead[E]
        end
 
        redef fun iterator: ArrayIterator[E] do return new ArrayIterator[E](self)
+       redef fun reverse_iterator do return new ArrayReverseIterator[E](self)
 end
 
 # Resizable one dimension array of objects.
@@ -364,6 +365,20 @@ private class ArrayIterator[E]
        var _array: AbstractArrayRead[E]
 end
 
+private class ArrayReverseIterator[E]
+       super ArrayIterator[E]
+
+       redef fun is_ok do return _index >= 0
+
+       redef fun next do _index -= 1
+
+       init(a: AbstractArrayRead[E])
+       do
+               _array = a
+               _index = a.length - 1
+       end
+end
+
 # Others collections ##########################################################
 
 # A set implemented with an Array.