Skip to content

Commit

Permalink
Add Hash.STORE(\keys,\values)
Browse files Browse the repository at this point in the history
Another way of creating a Hash internally, taking 2 iterables: one with
keys and one with values, that are supposed to generate an equal number
of values.  To be used in hyper operations.
  • Loading branch information
lizmat committed Nov 14, 2018
1 parent 80edefc commit faa19ab
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/Hash.pm6
Expand Up @@ -113,6 +113,16 @@ my class Hash { # declared in BOOTSTRAP

nqp::p6bindattrinvres(self,Map,'$!storage',$storage)
}
multi method STORE(Hash:D: \keys, \values) {
my \iterkeys := keys.iterator;
my \itervalues := values.iterator;
nqp::bindattr(self,Map,'$!storage',nqp::hash);
nqp::until(
nqp::eqaddr((my \key := iterkeys.pull-one),IterationEnd),
self.STORE_AT_KEY(key,itervalues.pull-one)
);
self
}

multi method ASSIGN-KEY(Hash:D: Str:D $key, Mu \assignval) is raw {
my \storage := nqp::getattr(self,Map,'$!storage');
Expand Down

0 comments on commit faa19ab

Please sign in to comment.