Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make all .at_key multi method with signature
  • Loading branch information
lizmat committed Jan 12, 2015
1 parent b55db85 commit af6200a
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/core/Bag.pm
Expand Up @@ -11,7 +11,7 @@ my class Bag does Baggy {
~ %!elems.keys.sort.map( { $_ ~ '(' ~ %!elems{$_}.value ~ ')' } );
}

method at_key($k --> Int) {
multi method at_key(Bag:D: $k --> Int) {
my $key := $k.WHICH;
%!elems.exists_key($key)
?? %!elems{$key}.value
Expand Down
2 changes: 1 addition & 1 deletion src/core/BagHash.pm
@@ -1,6 +1,6 @@
my class BagHash does Baggy {

method at_key($k) {
multi method at_key(BagHash:D: $k) {
Proxy.new(
FETCH => {
my $key := $k.WHICH;
Expand Down
15 changes: 6 additions & 9 deletions src/core/Capture.pm
Expand Up @@ -30,16 +30,13 @@ my class Capture { # declared in BOOTSTRAP
$WHICH;
}

multi method at_key(Capture:D: $key is copy) {
$key = $key.Str;
nqp::existskey($!hash, nqp::unbox_s($key))
?? nqp::atkey($!hash, nqp::unbox_s($key))
!! Any
multi method at_key(Capture:D: \key) {
my str $skey = nqp::unbox_s(key.Str);
nqp::existskey($!hash,$skey) ?? nqp::atkey($!hash, $skey) !! Any;
}
multi method at_key(Capture:D: Str $key) {
nqp::existskey($!hash, nqp::unbox_s($key))
?? nqp::atkey($!hash, nqp::unbox_s($key))
!! Any
multi method at_key(Capture:D: Str:D \key) {
my str $skey = nqp::unbox_s(key);
nqp::existskey($!hash,$skey) ?? nqp::atkey($!hash, $skey) !! Any;
}

multi method at_pos(Capture:D: $pos is copy) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Enum.pm
Expand Up @@ -45,7 +45,7 @@ my class Enum does Associative {
sprintf($format, $.key, $.value);
}

method at_key($key) {
multi method at_key(Enum:D: $key) {
$key eq $!key ?? $!value !! Mu
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/Hash.pm
Expand Up @@ -14,16 +14,16 @@ my class Hash { # declared in BOOTSTRAP
my Mu $storage := nqp::getattr(self, EnumMap, '$!storage');
$storage := nqp::bindattr(self, EnumMap, '$!storage', nqp::hash())
unless nqp::defined($storage);
my str $key = nqp::istype(key, Str) ?? key !! key.Str;
if nqp::existskey($storage, $key) {
nqp::atkey($storage, $key);
my str $skey = nqp::istype(key, Str) ?? key !! key.Str;
if nqp::existskey($storage, $skey) {
nqp::atkey($storage, $skey);
}
else {
nqp::p6bindattrinvres(
(my \v := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindkey($storage, $key, v) }
-> { nqp::bindkey($storage, $skey, v) }
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Mix.pm
Expand Up @@ -13,7 +13,7 @@ my class Mix does Mixy {
}

method total (--> Real) { $!total //= [+] self.values }
method at_key($k --> Real) {
multi method at_key(Mix:D: $k --> Real) {
my $key := $k.WHICH;
%!elems.exists_key($key)
?? %!elems{$key}.value
Expand Down
4 changes: 2 additions & 2 deletions src/core/MixHash.pm
@@ -1,9 +1,9 @@
my class MixHash does Mixy {

method at_key($k) {
multi method at_key(MixHash:D: $k) {
Proxy.new(
FETCH => {
my $key := $k.WHICH;
my $key := $k.WHICH;
%!elems.exists_key($key) ?? %!elems{$key}.value !! 0;
},
STORE => -> $, $value {
Expand Down
2 changes: 1 addition & 1 deletion src/core/PseudoStash.pm
Expand Up @@ -105,7 +105,7 @@ my class PseudoStash is EnumMap {
'$?PACKAGE')
};

method at_key($key is copy) is rw {
multi method at_key(PseudoStash:D: $key is copy) is rw {
$key = $key.Str;
my Mu $nkey := nqp::unbox_s($key);
if %pseudoers.exists_key($key) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/Set.pm
Expand Up @@ -13,8 +13,8 @@ my class Set does Setty {
self;
}

method at_key($k --> Bool) {
so %!elems.exists_key($k.WHICH);
multi method at_key(Set:D: \k --> Bool) {
so %!elems.exists_key(k.WHICH);
}

method delete_key($k --> Bool) is hidden_from_backtrace {
Expand Down
2 changes: 1 addition & 1 deletion src/core/SetHash.pm
@@ -1,6 +1,6 @@
my class SetHash does Setty {

method at_key($k --> Bool) {
multi method at_key(SetHash:D: $k --> Bool) {
Proxy.new(
FETCH => {
so %!elems.exists_key($k.WHICH);
Expand Down

0 comments on commit af6200a

Please sign in to comment.