Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: nom
Fetching contributors…

Cannot retrieve contributors at this time

40 lines (34 sloc) 1.34 kb
my class Mix does Mixy {
has Real $!total;
has $!WHICH;
has @!pairs;
multi method WHICH (Mix:D:) {
$!WHICH //= self.^name
~ '|'
~ %!elems.keys.sort.map( { $_ ~ '(' ~ %!elems{$_}.value ~ ')' } );
}
multi method pairs(Mix:D:) { # copy values otherwise we can change the Mix
@!pairs ||= %!elems.values.map: { Enum.new(:key(.key),:value(.value)) };
}
method total (--> Real) { $!total //= [+] self.values }
multi method at_key(Mix:D: $k --> Real) {
my $key := $k.WHICH;
%!elems.exists_key($key)
?? %!elems{$key}.value
!! 0;
}
method delete_key($a --> Real) is hidden_from_backtrace {
X::Immutable.new( method => 'delete_key', typename => self.^name ).throw;
}
multi method grab($count? --> Real) is hidden_from_backtrace {
X::Immutable.new( method => 'grab', typename => self.^name ).throw;
}
multi method grabpairs($count? --> Real) is hidden_from_backtrace {
X::Immutable.new( method => 'grabpairs', typename => self.^name ).throw;
}
method Mix { self }
method MixHash { MixHash.new-from-pairs(%!elems.values) }
method Bag { Bag.new-from-pairs(%!elems.values) }
method BagHash { BagHash.new-from-pairs(%!elems.values) }
}
# vim: ft=perl6 expandtab sw=4
Jump to Line
Something went wrong with that request. Please try again.