develooper Front page | perl.perl6.language | Postings from May 2021

Re: Correct enum incantation?

Thread Previous | Thread Next
From:
Fernando Santagata
Date:
May 5, 2021 23:59
Subject:
Re: Correct enum incantation?
Message ID:
CAJ+jyGg+SRWn7+cM-OXy0SjgJi26+Xpo62QthhsupoT4nsTb8A@mail.gmail.com
On Wed, May 5, 2021 at 6:00 PM William Michels via perl6-users <
perl6-users@perl.org> wrote:

> Hello,
>
> I've been reading over an interesting Answer on StackOverflow by wamba:
>
> https://stackoverflow.com/a/67324175/7270649
>
> I started trying to explore enums on my own and quickly realized that
> method calls on enums are different from simple key/value pairs. For enums,
> calling a `.key` or `.value` or `.kv` method won't work. Instead one must
> use something like `.^enum_values` or `.^enum_value_list`.
>

Probably you need the new and shiny compiler ;)

> $*RAKU.compiler.version
v2021.04
> Month.keys
(oct dec aug jun mar apr feb nov jul may sep jan)
> Month.values
(11 6 9 2 5 7 3 12 8 4 10 1)
> .say for Month.kv
nov
11
jul
7
sep
9
jan
1
oct
10
mar
3
jun
6
apr
4
aug
8
dec
12
feb
2
may
5
-- 
Fernando Santagata

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About