Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make .exists_key a multi and some opts
  • Loading branch information
lizmat committed Jan 12, 2015
1 parent af6200a commit e320eb4
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
5 changes: 4 additions & 1 deletion src/core/Any.pm
Expand Up @@ -15,7 +15,10 @@ my class Any { # declared in BOOTSTRAP
# primitives
method infinite() { Nil }

method exists_key($key) { False }
proto method exists_key(|){ * }
multi method exists_key(Any:U: $) { False }
multi method exists_key(Any:D: $) { False }

proto method exists_pos(|) { * }
multi method exists_pos(Any:U: $pos) { False }
multi method exists_pos(Any:D: $pos) { $pos == 0 }
Expand Down
2 changes: 1 addition & 1 deletion src/core/Baggy.pm
Expand Up @@ -13,7 +13,7 @@ my role Baggy does QuantHash {
method kxxv { %!elems.values.map( {.key xx .value} ) }
method elems(--> Int) { %!elems.elems }
method total(--> Int) { [+] self.values }
method exists_key($k --> Bool) {
multi method exists_key(Baggy:D: $k --> Bool) {
%!elems.exists_key($k.WHICH);
}
method Bool { %!elems.Bool }
Expand Down
7 changes: 5 additions & 2 deletions src/core/Capture.pm
Expand Up @@ -57,8 +57,11 @@ my class Capture { # declared in BOOTSTRAP
$enum;
}

method exists_key(Capture:D: $key ) {
nqp::p6bool(nqp::existskey($!hash, nqp::unbox_s($key.Str)));
multi method exists_key(Capture:D: Str:D \key ) {
nqp::p6bool(nqp::existskey($!hash, nqp::unbox_s(key)));
}
multi method exists_key(Capture:D: \key ) {
nqp::p6bool(nqp::existskey($!hash, nqp::unbox_s(key.Str)));
}

method list(Capture:D:) {
Expand Down
9 changes: 2 additions & 7 deletions src/core/Enum.pm
Expand Up @@ -45,13 +45,8 @@ my class Enum does Associative {
sprintf($format, $.key, $.value);
}

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

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

method FLATTENABLE_LIST() { nqp::list() }
method FLATTENABLE_HASH() { nqp::hash($!key, $!value) }
Expand Down
2 changes: 0 additions & 2 deletions src/core/EnumMap.pm
Expand Up @@ -25,8 +25,6 @@ my class EnumMap does Associative { # declared in BOOTSTRAP
so self.keys.any.match($topic);
}

proto method exists_key(|) {*}
multi method exists_key(EnumMap:U:) { False }
multi method exists_key(EnumMap:D: Str:D \key) {
nqp::p6bool(
nqp::defined($!storage)
Expand Down
3 changes: 2 additions & 1 deletion src/core/PseudoStash.pm
Expand Up @@ -155,7 +155,8 @@ my class PseudoStash is EnumMap {
die "This case of binding is not yet implemented";
}
}
method exists_key($key is copy) {
# for some reason we get a ambiguous dispatch error by making this a multi
method exists_key(PseudoStash:D: $key is copy) {
$key = $key.Str;
if %pseudoers.exists_key($key) {
True
Expand Down
2 changes: 1 addition & 1 deletion src/core/Setty.pm
Expand Up @@ -12,7 +12,7 @@ my role Setty does QuantHash {
method total(--> Int) { %!elems.elems }
method minpairs(--> List) { self.pairs }
method maxpairs(--> List) { self.pairs }
method exists_key($k --> Bool) {
multi method exists_key(Setty:D: $k --> Bool) {
so ( %!elems && nqp::existskey(%!elems, nqp::unbox_s($k.WHICH)) );
}
multi method Bool(Setty:D:) { %!elems.Bool }
Expand Down

0 comments on commit e320eb4

Please sign in to comment.