Skip to content

Commit

Permalink
Implement Parcel.rotate
Browse files Browse the repository at this point in the history
One wonders whether the internal logic would warrant an nqp::rotate op, which
could then be shared with List.rotate
  • Loading branch information
lizmat committed Oct 22, 2013
1 parent e9830d3 commit b0c90ed
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/core/Parcel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ my class Parcel does Positional { # declared in BOOTSTRAP
method list() { nqp::p6list(nqp::clone($!storage), List, Mu) }
method lol() { nqp::p6list(nqp::clone($!storage), LoL, Mu) }

method rotate (Int $n is copy = 1) {
my Mu $storage := nqp::clone($!storage);
$n %= nqp::p6box_i(nqp::elems($!storage));
if $n > 0 {
nqp::push($storage, nqp::shift($storage)) while $n--;
}
elsif $n < 0 {
nqp::unshift($storage, nqp::pop($storage)) while $n++;
}
my $parcel := nqp::create(self.WHAT);
nqp::bindattr($parcel, Parcel, '$!storage', $storage);
$parcel;
}

method at_pos(Parcel:D: \x) is rw { self.flat.at_pos(x); }

proto method postcircumfix:<[ ]>(|) { * }
Expand Down

0 comments on commit b0c90ed

Please sign in to comment.