Skip to content
Browse files

port List.ACCEPTS back from b

* gets Whatever special handling for lists back.
  • Loading branch information...
1 parent e1f5d99 commit f17d339185c95e4b3b17230cb9b93032578e2a53 @coke coke committed Apr 15, 2013
Showing with 25 additions and 6 deletions.
  1. +25 −6 src/core/List.pm
View
31 src/core/List.pm
@@ -279,13 +279,32 @@ my class List does Positional {
}
multi method ACCEPTS(List:D: $topic) {
- my @t = $topic.list;
- # TODO: Whatever-DWIMmery
- return False unless self.elems == @t.elems;
- for ^self.elems {
- return False unless self.at_pos($_) === @t[$_];
+ my $sseq = self;
+ my $tseq = $topic.list;
+
+ my $spos = 0;
+ my $tpos = 0;
+ while $spos < +$sseq {
+ # if the next element is Whatever
+ if $sseq[$spos] ~~ Whatever {
+ # skip over all of the Whatevers
+ $spos++ while $spos <= +$sseq && $sseq[$spos] ~~ Whatever;
+ # if nothing left, we're done
+ return True if !($spos < +$sseq);
+ # find a target matching our new target
+ $tpos++ while ($tpos < +$tseq) && $tseq[$tpos] !== $sseq[$spos];
+ # return false if we ran out
+ return False if !($tpos < +$tseq);
+ }
+ elsif $tpos >= +$tseq || $tseq[$tpos] !=== $sseq[$spos] {
+ return False;
+ }
+ # skip matching elements
+ $spos++;
+ $tpos++;
}
- True;
+ # If nothing left to match, we're successful.
+ $tpos >= +$tseq;
}
method classify(&test) {

0 comments on commit f17d339

Please sign in to comment.
Something went wrong with that request. Please try again.