Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix partials error handling:

  Once you return a lazy list, you cannot decide instead to return a
  Failure instead during the iteration of the list.  Or in other words,
  Perl6 does not make time-travel possible.  Who would have thunk it? :-)
  • Loading branch information...
commit 62b3e4562b2930e2409c7c63804724d6726ade6f 1 parent 7587447
@skids authored
Showing with 20 additions and 4 deletions.
  1. +2 −3 lib/Sum.pm6
  2. +18 −1 t/sum.t
View
5 lib/Sum.pm6
@@ -281,10 +281,9 @@ role Sum::Partial {
method partials (*@addends --> List) {
flat self.marshal(|@addends).map: {
- # XXX should we return a list with all Failures in it instead?
- return($^addend) if $addend ~~ Failure;
+ last($^addend) if $addend ~~ Failure;
given self.add($addend) {
- when Failure { return $_ };
+ when Failure { last $_ };
}
self.finalize;
}
View
19 t/sum.t
@@ -3,7 +3,7 @@ BEGIN { @*INC.unshift: './lib'; }
use Test;
-plan 64;
+plan 66;
use Sum;
ok(1,'We use Sum and we are still alive');
@@ -119,6 +119,23 @@ my @d;
#? rakudo skip 'feed through a slurpy arity function'
#@d <== $h.partials <== (2,3);
#is @d.join(""), "3942", "partials inserts values in a feed"
+is $h.partials(4,5,Failure.new(X::AdHoc.new()),6).map({.WHAT.gist}), 'Int() Int() Failure()', "partials stops iterating on Failure (Partial,Cooked).";
+
+class Foo3r does Sum does Sum::Partial does Sum::Marshal::Raw {
+ has $.accum is rw = 0;
+ method finalize (*@addends) {
+ self.push(@addends);
+ $.accum;
+ }
+ method Numeric () { self.finalize };
+ method add (*@addends) {
+ $.accum += [+] @addends;
+ };
+}
+my Foo3r $hr .= new();
+
+# XXX do some tests of laziness of partials method
+is $hr.partials(4,5,Failure.new(X::AdHoc.new()),6).map({.WHAT.gist}), 'Int() Int() Failure()', "partials stops iterating on Failure (Partial,Raw).";
lives_ok {
class Foo4 does Sum does Sum::Partial does Sum::Marshal::StrOrds {
Please sign in to comment.
Something went wrong with that request. Please try again.