Skip to content

Instantly share code, notes, and snippets.

Created August 24, 2015 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7de488bc83a3eee77948 to your computer and use it in GitHub Desktop.
Save anonymous/7de488bc83a3eee77948 to your computer and use it in GitHub Desktop.
diff --git a/src/core/metaops.pm b/src/core/metaops.pm
index 2ef2d30..8a81f74 100644
--- a/src/core/metaops.pm
+++ b/src/core/metaops.pm
@@ -399,11 +399,11 @@ multi sub HYPER(&operator, Iterable:D \left, Iterable:D \right, :$dwim-left, :$d
has $!whatever;
has $!i;
has $!elems;
- method new(\source, $ended is rw) {
+ method new(\source) {
my $iter := self.CREATE;
nqp::bindattr($iter, self, '$!source', source);
nqp::bindattr($iter, self, '$!buffer', IterationBuffer.new);
- nqp::bindattr($iter, self, '$!ended', $ended);
+ nqp::bindattr($iter, self, '$!ended', False);
nqp::bindattr($iter, self, '$!whatever', False);
nqp::bindattr($iter, self, '$!i', 0);
nqp::bindattr($iter, self, '$!elems', 0);
@@ -421,12 +421,12 @@ multi sub HYPER(&operator, Iterable:D \left, Iterable:D \right, :$dwim-left, :$d
else {
my \value := $!source.pull-one;
if value =:= IterationEnd {
- $!ended = True;
+ $!ended := True;
$!elems == 0 ?? value !! self.pull-one()
}
elsif nqp::istype(value, Whatever) {
$!whatever := True;
- $!ended = True;
+ $!ended := True;
self.pull-one()
}
else {
@@ -436,6 +436,7 @@ multi sub HYPER(&operator, Iterable:D \left, Iterable:D \right, :$dwim-left, :$d
}
}
}
+ method ended() { $!ended }
method count-elems() {
unless ($!ended) {
$!elems := $!elems + 1 until $!source.pull-one =:= IterationEnd;
@@ -444,23 +445,20 @@ multi sub HYPER(&operator, Iterable:D \left, Iterable:D \right, :$dwim-left, :$d
}
}
- my $left-ended = False;
- my $right-ended = False;
- my \lefti := DwimIterator.new(left-iterator, $left-ended);
- my \righti := DwimIterator.new(right-iterator, $right-ended);
+ my \lefti := DwimIterator.new(left-iterator);
+ my \righti := DwimIterator.new(right-iterator);
my \result := IterationBuffer.new;
loop {
my \leftv := lefti.pull-one;
my \rightv := righti.pull-one;
- last if ($dwim-left and $dwim-right)
- ?? ($left-ended and $right-ended)
- !! (($dwim-left or $left-ended) and ($dwim-right or $right-ended));
- last if $++ == 0 and ($dwim-left and $left-ended or $dwim-right and $right-ended);
-
X::HyperOp::NonDWIM.new(:&operator, :left-elems(lefti.count-elems), :right-elems(righti.count-elems)).throw
- if leftv =:= IterationEnd or rightv =:= IterationEnd;
+ if !$dwim-left and !$dwim-right and (lefti.ended != righti.ended);
+
+ last if ($dwim-left and $dwim-right) ?? (lefti.ended and righti.ended) !!
+ (($dwim-left or lefti.ended) and ($dwim-right or righti.ended));
+ last if $++ == 0 and ($dwim-left and lefti.ended or $dwim-right and righti.ended);
result.push(HYPER(&operator, leftv, rightv, :$dwim-left, :$dwim-right));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment