Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make sure that Mixy allows for negative values when building
  • Loading branch information
lizmat committed Oct 4, 2013
1 parent 9f6f443 commit be96b97
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/core/Mixy.pm
Expand Up @@ -3,6 +3,22 @@ my role Mixy does Baggy { # should really be QuantHash, but that's for later
method default(--> Real) { 0 }
method total(--> Real) { [+] self.values }

method new-fp(*@pairs --> Mixy) {
my %e;
for @pairs {
when Pair {
(%e{$_.key.WHICH} //= ($_.key => 0)).value += $_.value;
}
default {
(%e{$_.WHICH} //= ($_ => 0)).value++;
}
}
for %e -> $p {
%e.delete_key($p.key) if $p.value.value == 0;
}
self.bless(:elems(%e));
}

multi method gist(Mixy:D $ : --> Str) {
my $name := self.^name;
( $name eq 'Mix' ?? 'mix' !! "$name.new" )
Expand Down

0 comments on commit be96b97

Please sign in to comment.