Skip to content
Permalink
Browse files

Make QuantHash/Setty roles parameterizable

As a first step to making all QuantHashes parameterizable roles.
  • Loading branch information...
lizmat committed Jan 13, 2019
1 parent 7be075e commit 0d9e9f34ce481e28228762d6fec0add90c4c6a81
Showing with 10 additions and 10 deletions.
  1. +9 −9 src/core/QuantHash.pm6
  2. +1 −1 src/core/Setty.pm6
@@ -1,8 +1,8 @@
my role QuantHash does Associative {
my role QuantHash[::CONSTRAINT = Mu] does Associative {

method keyof() { Any }
method keyof(::?CLASS:D:) { CONSTRAINT }

method SET-SELF(QuantHash:D: \elems) { # cannot be a private method
method SET-SELF(::?CLASS:D: \elems) { # cannot be a private method
nqp::stmts(
nqp::if(
nqp::elems(elems),
@@ -18,17 +18,17 @@ my role QuantHash does Associative {
X::Assignment::RO.new(value => self).throw
}

method Int ( --> Int:D) { self.total.Int }
method Num ( --> Num:D) { self.total.Num }
method Numeric ( --> Numeric:D) { self.total.Numeric }
method Real ( --> Real:D) { self.total.Real }
method Int (::?CLASS:D: --> Int:D) { self.total.Int }
method Num (::?CLASS:D: --> Num:D) { self.total.Num }
method Numeric (::?CLASS:D: --> Numeric:D) { self.total.Numeric }
method Real (::?CLASS:D: --> Real:D) { self.total.Real }

method Capture() { self.Hash.Capture }
method Capture(::?CLASS:D:) { self.Hash.Capture }

multi method list(QuantHash:U:) { self.Any::list }
multi method list(QuantHash:D:) { self.pairs.cache }

method fmt(QuantHash: Cool $format = "%s\t\%s", $sep = "\n") {
method fmt(::?CLASS: Cool $format = "%s\t\%s", $sep = "\n") {
nqp::iseq_i(nqp::sprintfdirectives( nqp::unbox_s($format.Stringy)),1)
?? self.keys.fmt($format, $sep)
!! self.pairs.fmt($format, $sep)
@@ -1,4 +1,4 @@
my role Setty does QuantHash {
my role Setty[::CONSTRAINT = Mu] does QuantHash[CONSTRAINT] {
has Rakudo::Internals::IterationSet $!elems; # key.WHICH => key

method of() { Bool }

0 comments on commit 0d9e9f3

Please sign in to comment.
You can’t perform that action at this time.