Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add (Typed)Hash method "keyof"

Not sure where to spec this, and whether the name is ok
  • Loading branch information...
commit cd927656d7a1a379c50cd4cf10edfc4bb66a6857 1 parent d990eee
@lizmat lizmat authored
Showing with 2 additions and 0 deletions.
  1. +2 −0  src/core/Hash.pm
View
2  src/core/Hash.pm
@@ -8,6 +8,7 @@ my class Hash {
%h.STORE(@args) if @args;
%h;
}
+ method keyof () { Any }
multi method at_key(Hash:D: $key is copy) is rw {
my Mu $storage := nqp::defined(nqp::getattr(self, EnumMap, '$!storage')) ??
@@ -191,6 +192,7 @@ my class Hash {
}
my role TypedHash[::TValue, ::TKey] does Associative[TValue] {
has $!keys;
+ method keyof () { TKey }
method at_key(::?CLASS:D: TKey \key, TValue $v? is copy) is rw {
my $key_which = key.WHICH;
self.exists(key)

2 comments on commit cd92765

@xfix

@MattOates: I think it's bad method name (talking about Ruby now, I would assume it gets the value for given key, just like []). Besides, this doesn't get key for value, but gets the type of value typed hash expects.

Perhaps key-type or something would be better.

> Hash[Str, Int].new.keyof
(Int)
Please sign in to comment.
Something went wrong with that request. Please try again.