Skip to content

Commit

Permalink
Make .produce/.reduce nodal the correct way
Browse files Browse the repository at this point in the history
The intent seems to be that they should be nodal, but they way this
was implemented, hid the "is nodal" functionality.

Simplify the actually working candidate to not need a temporary variable
or an -if- statement: if the lookup for the reducer fails, a Failure will
be returned, which will throw as soon as it is attempted to be executed.

Also implement a candidate for handling type objects: there should be
no reason for doing that at runtime repeatedly.

This breaks tests 134/135 in S03-metaops/hyper.t .  However, these tests
seem to assume non-nodality.

This may also have breaking consequences in the ecosystem: a special note
in the release message / a p6alert seems to be in order if this change is
going to make it to the next release.
  • Loading branch information
lizmat committed Mar 20, 2018
1 parent ec5416a commit 08eb465
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/core/Any-iterable-methods.pm6
Expand Up @@ -1459,18 +1459,16 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
)
}

proto method reduce(|) {*}
multi method reduce(&with) is nodal {
return unless self.DEFINITE;
my $reducer := find-reducer-for-op(&with);
$reducer(&with)(self) if $reducer;
}

proto method produce(|) {*}
multi method produce(&with) is nodal {
return unless self.DEFINITE;
my $reducer := find-reducer-for-op(&with);
$reducer(&with,1)(self) if $reducer;
proto method reduce(|) is nodal {*}
multi method reduce(Any:U: & --> Nil) { }
multi method reduce(Any:D: &with) {
(find-reducer-for-op(&with))(&with)(self)
}

proto method produce(|) is nodal {*}
multi method produce(Any:U: & --> Nil) { }
multi method produce(Any:D: &with) {
(find-reducer-for-op(&with))(&with,1)(self)
}

proto method unique(|) is nodal {*}
Expand Down

0 comments on commit 08eb465

Please sign in to comment.