Thanks for all the answers. This will get me going.
I was unaware of the ' Hash[Int, Str]' type of declarative syntax.
I knew Hash[Str] was a thing but was unaware of the '[Int,Str]' type of
syntax.
Thanks for the insight!
On Sat, Feb 1, 2020 at 11:16 AM Elizabeth Mattijsen wrote:
> subset
subset PhoneNumber of Int where *.chars == 9; # or any other constraint
constant PhoneBook = Hash[PhoneNumber, Str]; # no need to make a class, a
type suffices
my %pb is PhoneBook = foo => 123456789;
dd %pb; # (my PhoneNumber %{Str} = :foo(123456789))
I wouldn't use a subset like this:
subset PhoneBook of Hash[Int, Str];
I would instead use a constant:
constant PhoneBook = Hash[Int, Str];
Then you can use that for creating new instances.
PhoneBook.new(); # Hash[Int, Str].new()
# or
my %pb is PhoneBook; # my Int %pb{Str};
On Sat, 01 Feb 2020, Paul Procacci wrote:
> Hey ladies/gents,
>
> How would one go about defining a subset of a Hash who's key's and values
> are both constrained by something
>
> I've read https://docs.perl6.org/type/Hash and it does make mention of
> constraining keys and values, but not w
Hey ladies/gents,
How would one go about defining a subset of a Hash who's key's and values
are both constrained by something
I've read https://docs.perl6.org/type/Hash and it does make mention of
constraining keys and values, but not within the context of a subset.
Before I go ripping my ha