Re: Correct enum incantation?
[email protected] (Fernando Santagata) Wed, 5 May 2021 18:24:26 +0100
| Newsgroups | perl.perl6.language |
|---|---|
| Message-ID | <CAJ+jyGg+SRWn7+cM-OXy0SjgJi26+Xpo62QthhsupoT4nsTb8A@mail.gmail.com> |
--0000000000001ae73c05c19878b4 Content-Type: text/plain; charset="UTF-8" On Wed, May 5, 2021 at 6:00 PM William Michels via perl6-users < [email protected]> 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 --0000000000001ae73c05c19878b4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail= _attr">On Wed, May 5, 2021 at 6:00 PM William Michels via perl6-users <<= a href=3D"mailto:[email protected]">[email protected]</a>> wrote:<= br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e= x;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"= >Hello,<br><br>I've been reading over an interesting Answer on StackOve= rflow by wamba:<br><br><a href=3D"https://stackoverflow.com/a/67324175/7270= 649" target=3D"_blank">https://stackoverflow.com/a/67324175/7270649</a><br>= <br>I started trying to explore enums on my own and quickly realized that m= ethod 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 mu= st use something like `.^enum_values` or `.^enum_value_list`.<br></div></bl= ockquote><div><br></div><div><div style=3D"color:rgb(0,0,0)" class=3D"gmail= _default">Probably you need the new and shiny compiler ;)</div><br></div><d= iv><div style=3D"color:rgb(0,0,0)" class=3D"gmail_default"><span class=3D"g= mail_default" style=3D"color:rgb(0,0,0)"></span>> $*RAKU.compiler.versio= n<br><div class=3D"gmail_quote"><div>v2021.04</div></div></div></div><div>&= gt; Month.keys<br>(oct dec aug jun mar apr feb nov jul may sep jan)</div><d= iv><div style=3D"color:rgb(0,0,0)" class=3D"gmail_default">> Month.value= s<br></div>(11 6 9 2 5 7 3 12 8 4 10 1)<br>> .say for Month.kv<br>nov<br= >11<br>jul<br>7<br>sep<br>9<br>jan<br>1<br>oct<br>10<br>mar<br>3<br>jun<br>= 6<br>apr<br>4<br>aug<br>8<br>dec<br>12<br>feb<br>2<br>may<br>5<br></div><di= v><span class=3D"gmail_default" style=3D"color:rgb(0,0,0)"></span></div></d= iv>-- <br><div dir=3D"ltr" class=3D"gmail_signature">Fernando Santagata</di= v></div> --0000000000001ae73c05c19878b4--