Skip to content

Commit

Permalink
Override List's reverse method
Browse files Browse the repository at this point in the history
And get rid of `reversed` as `reverse` now returns a new `WalkList`
instance.
  • Loading branch information
vrurg committed Dec 12, 2019
1 parent 1aad348 commit 4a962e0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/core.c/WalkList.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
my class WalkList is List {
has Mu $.invocant;
has $.quiet = False;
has $.reverse = False;

method new(|) {
callsame.quiet(False).reversed(False)
callsame.quiet(False)
}

proto method invoke(|) {*}
multi method invoke(::?CLASS:D: Capture:D $args) {
my @rv;
for |($!reverse ?? self.List::reverse !! self) -> &method {
@rv.push: $($!invocant.&method(|$args));
for |self -> &method {
my $val = $!invocant.&method(|$args);
@rv.push: $val ~~ Slip ?? $val.List !! $val;
CATCH {
default {
$_.throw unless $!quiet;
Expand All @@ -32,9 +32,10 @@ my class WalkList is List {
self
}

method reversed(::?CLASS:D: Bool() $reverse = True --> ::?CLASS:D) {
$!reverse = $reverse;
self
method reverse(::?CLASS:D: --> ::?CLASS:D) {
self.WHAT.new(|self.List::reverse)
.set_invocant($!invocant)
.quiet($!quiet)
}

method set_invocant(::?CLASS:D: Mu \inv) {
Expand Down

0 comments on commit 4a962e0

Please sign in to comment.