Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add sanity test on Supply.merge/zip/zip-latest
  • Loading branch information
lizmat committed Dec 21, 2014
1 parent c908f98 commit e2adfae
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/core/Supply.pm
Expand Up @@ -4,6 +4,10 @@
# to SupplyOperations.

my class SupplyOperations { ... }
my class X::Supply::Combinator is Exception {
has $.combinator;
method message() { "Can only use $!combinator to combine defined Supply objects" }
}

my class Tap {
has &.emit;
Expand Down Expand Up @@ -699,9 +703,13 @@ my role Supply {
method sort(Supply:D: &by = &infix:<cmp>) { self.grab( {.sort(&by)} ) }

method merge(*@s) {

@s.unshift(self) if self.DEFINITE; # add if instance method
return Supply unless +@s; # nothing to be done

X::Supply::Combinator.new(
combinator => 'merge'
).throw if NOT_ALL_DEFINED_TYPE(@s,Supply);

return @s[0] if +@s == 1; # nothing to be done

my $dones = 0;
Expand All @@ -714,9 +722,13 @@ my role Supply {
}

method zip(*@s, :&with is copy = &[,]) {

@s.unshift(self) if self.DEFINITE; # add if instance method
return Supply unless +@s; # nothing to be done

X::Supply::Combinator.new(
combinator => 'zip'
).throw if NOT_ALL_DEFINED_TYPE(@s,Supply);

return @s[0] if +@s == 1; # nothing to be done

my @values = ( [] xx +@s );
Expand All @@ -733,6 +745,11 @@ my role Supply {
method zip-latest(*@s, :&with is copy = &[,], :$initial ) {
@s.unshift(self) if self.DEFINITE; # add if instance method
return Supply unless +@s; # nothing to do.

X::Supply::Combinator.new(
combinator => 'zip-latest'
).throw if NOT_ALL_DEFINED_TYPE(@s,Supply);

return @s[0] if +@s == 1; # nothing to do.

my @values;
Expand Down

0 comments on commit e2adfae

Please sign in to comment.