Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement reverse_each().
Signed-off-by: Ted Reed <ted.reed@gmail.com>
  • Loading branch information
dtm authored and treed committed Jul 28, 2009
1 parent ecc08a4 commit 166f0ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/classes/Array.pir
Expand Up @@ -1054,6 +1054,22 @@ Run C<block> once for each item in C<self>, with the item passed as an arg.
each_loop_end:
.end

=item each(block)

Run C<block> once for each item in C<self> starting from the end, with the item passed as an arg.

=cut
.sub 'reverse_each' :method
.param pmc block :named('!BLOCK')
.local int count
count = elements self
each_loop:
dec count
$P0 = self[count]
block($P0)
if count > 0 goto each_loop
.end

=item collect(block)

Run C<block> once for each item in C<self>, with the item passed as an arg.
Expand Down
8 changes: 7 additions & 1 deletion t/array/array.t
@@ -1,6 +1,6 @@
require 'Test'
include Test
plan 18
plan 22

a = [ 1, 2, 3, 4 ]

Expand Down Expand Up @@ -42,3 +42,9 @@ a.each_with_index() do |x, i|
is x, i
end

a = [ 3, 2, 1, 0]
n = 0
a.reverse_each() do |x|
is x, n
n+=1
end

0 comments on commit 166f0ee

Please sign in to comment.