Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make .total constant attribute for Set/Bag/Mix
  • Loading branch information
lizmat committed Oct 4, 2013
1 parent 4fd3721 commit c962e51
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/core/Bag.pm
@@ -1,10 +1,13 @@
my class Bag does Baggy {
has Int $!total;
has $!WHICH;

submethod total { $!total }
submethod WHICH { $!WHICH }
submethod BUILD (:%elems) {
my @keys := %elems.keys.sort;
$!WHICH = self.^name
$!total := [+] %elems.values.map: {.value};
$!WHICH := self.^name
~ '|'
~ @keys.map( { $_ ~ '(' ~ %elems{$_}.value ~ ')' } );
nqp::bindattr(self, Bag, '%!elems', %elems);
Expand Down
1 change: 0 additions & 1 deletion src/core/Mix.pm
@@ -1,5 +1,4 @@
my class Mix does Mixy {
has $!WHICH;

method at_key($k --> Real) {
my $elems := nqp::getattr(self, Mix, '%!elems');
Expand Down
5 changes: 4 additions & 1 deletion src/core/Set.pm
@@ -1,10 +1,13 @@
my class Set does Setty {
has Int $!total;
has $!WHICH;

submethod total { $!total }
submethod WHICH { $!WHICH }
submethod BUILD (:%elems) {
my @keys := %elems.keys.sort;
$!WHICH = self.^name ~ '|' ~ @keys.sort;
$!total := %elems.elems;
$!WHICH := self.^name ~ '|' ~ @keys.sort;
nqp::bindattr(self, Set, '%!elems', %elems);
}

Expand Down

0 comments on commit c962e51

Please sign in to comment.