Skip to content

Commit

Permalink
Revert "Revert "Map/map! are collect/collect!. Fix for collect! retur…
Browse files Browse the repository at this point in the history
…n val.""

This reverts commit bf88c4d.

Signed-off-by: Ted Reed <ted.reed@gmail.com>
  • Loading branch information
dtm authored and treed committed Aug 10, 2009
1 parent 217bfa0 commit fa95b37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/classes/Array.pir
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,11 @@ Creates a new Array containing the results and returns it.
.return (result)
.end

.sub 'map' :method
.param pmc block :named( "!BLOCK" )
.tailcall self.'collect'( "!BLOCK" => block )
.end

.sub 'collect!' :method
.param pmc block :named('!BLOCK')
.local int i, len
Expand All @@ -1158,8 +1163,15 @@ Creates a new Array containing the results and returns it.
goto loop

done:
.return (self)
.end

.sub 'map!' :method
.param pmc block :named( "!BLOCK" )
.tailcall self.'collect!'( "!BLOCK" => block )
.end


=item flatten

recursively flatten any inner arrays into a single outer array
Expand Down Expand Up @@ -2173,7 +2185,7 @@ Returns the elements of LIST in the opposite order.
.return(array)
.end

## TODO: join map reduce sort zip
## TODO: join reduce sort zip

=back

Expand Down
5 changes: 4 additions & 1 deletion t/array/collect.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'Test'
include Test
plan 3
plan 4

a = [ "a", "b", "c", "d" ]
b = a.collect {|x| x + "!" }
Expand All @@ -10,3 +10,6 @@ is b, [ "a!", "b!", "c!", "d!" ], ".collect on Array returns new array"

a.collect! {|x| x + "?"}
is a, ["a?","b?","c?","d?"], ".collect!"

b=a.collect! {|x| x + "!"}
is b, ["a?!","b?!","c?!","d?!"], ".collect!"

0 comments on commit fa95b37

Please sign in to comment.