Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

79 lines (58 sloc) 1.61 KB
#! nqp
ResizablePMCArray Methods
These methods extend Parrot's ResizablePMCArray type to include
more methods typical of Perl 6 lists and arrays.
module ResizablePMCArray {
=begin item delete
Remove item at C<$pos>
=end item
method delete($pos) {
pir::delete(self, $pos);
=begin item exists
Return true if item exists at C<$pos>
=end item
method exists($pos) {
pir::exists(self, $pos);
=begin item join
Return all elements joined by $sep.
=end item
method join ($separator = '') {
pir::join($separator, self);
=begin item map
Return an array with the results of applying C<&code> to
each element of the invocant. Note that NQP doesn't have
a flattening list context, so the number of elements returned
is exactly the same as the original.
=end item
method map (&code) {
my @mapped;
for self { @mapped.push( &code($_) ); }
=begin item grep
Return an array with elements matching code.
=end item
method grep (&code) {
my @grepped;
for self { @grepped.push($_) if &code($_) };
=begin item reverse
Return a reversed copy of the invocant.
=end item
method reverse () {
my @reversed;
for self { @reversed.unshift($_); }
our sub join ($separator, *@values) { @values.join($separator); }
our sub map (&code, *@values) {; }
our sub grep (&code, *@values) { @values.grep(&code); }
our sub list (*@values) { @values; }
# vim: ft=perl6
Jump to Line
Something went wrong with that request. Please try again.