Skip to content

Commit

Permalink
Make QuantHash/Setty roles parameterizable
Browse files Browse the repository at this point in the history
As a first step to making all QuantHashes parameterizable roles.
  • Loading branch information
lizmat committed Jan 13, 2019
1 parent 7be075e commit 0d9e9f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/core/QuantHash.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),
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/core/Setty.pm6
@@ -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 }
Expand Down

0 comments on commit 0d9e9f3

Please sign in to comment.