1. my role QuantHash does Associative {
  2. method Int ( --> Int:D) { self.total.Int }
  3. method Num ( --> Num:D) { self.total.Num }
  4. method Numeric ( --> Numeric:D) { self.total.Numeric }
  5. method Real ( --> Real:D) { self.total.Real }
  6. method list() { self.pairs.cache }
  7. method fmt(QuantHash: Cool $format = "%s\t\%s", $sep = "\n") {
  8. nqp::iseq_i(nqp::sprintfdirectives( nqp::unbox_s($format.Stringy)),1)
  9. ?? self.keys.fmt($format, $sep)
  10. !! self.pairs.fmt($format, $sep)
  11. }
  12. multi method AT-KEY(QuantHash:U \SELF: $key) is raw {
  13. nqp::istype(self, Set) || nqp::istype(self, Bag) || nqp::istype(self, Mix)
  14. ?? die "Cannot auto-vivify an immutable {SELF.^name}"
  15. !! (SELF = self.new).AT-KEY($key)
  16. }
  17. multi method pairs(QuantHash:D:) { Seq.new(self.iterator) }
  18. }