Skip to content
Permalink
Browse files

Make Bag.WHICH return a ValueObjAt

  • Loading branch information...
lizmat committed Dec 28, 2018
1 parent 0d29768 commit ca8d8afc712c0b51e5806179c04530694922c2ca
Showing with 18 additions and 8 deletions.
  1. +18 −8 src/core/Bag.pm6
@@ -1,17 +1,27 @@
my class Bag does Baggy {
has Int $!total;
has $!WHICH;
has ValueObjAt $!WHICH;
has Int $!total;

#--- introspection methods
multi method WHICH(Bag:D:) {
multi method WHICH(Bag:D: --> ValueObjAt:D) {
nqp::if(
nqp::attrinited(self,Bag,'$!WHICH'),
$!WHICH,
$!WHICH := ValueObjAt.new('Bag!' ~ nqp::sha1(
nqp::join('\0',Rakudo::Sorting.MERGESORT-str(
Rakudo::QuantHash.BAGGY-RAW-KEY-VALUES(self)
))
))
$!WHICH := nqp::box_s(
nqp::concat(
nqp::if(
nqp::eqaddr(self.WHAT,Bag),
'Bag|',
nqp::concat(nqp::unbox_s(self.^name), '|')
),
nqp::sha1(
nqp::join('\0',Rakudo::Sorting.MERGESORT-str(
Rakudo::QuantHash.BAGGY-RAW-KEY-VALUES(self)
))
)
),
ValueObjAt
)
)
}
method total(Bag:D: --> Int:D) {

0 comments on commit ca8d8af

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