Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make Bag.WHICH on demand and remove old cruft
  • Loading branch information
lizmat committed May 16, 2014
1 parent 2e49610 commit b700214
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/core/Bag.pm
Expand Up @@ -4,14 +4,12 @@ my class Bag does Baggy {

method total (--> Int) { $!total //= [+] self.values }

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

method at_key($k --> Int) {
my $key := $k.WHICH;
Expand Down

0 comments on commit b700214

Please sign in to comment.