Skip to content
Newer
Older
100644 45 lines (33 sloc) 1.12 KB
434bab6 @pmichaud Add Enum, Pair, .pairs method, and enum/hash flattening.
pmichaud authored Jun 18, 2011
1 my class Enum {
16bb82c @jnthn key and value should declare themselves as public attributes in Enum.
jnthn authored Sep 14, 2011
2 has $.key;
3 has $.value;
434bab6 @pmichaud Add Enum, Pair, .pairs method, and enum/hash flattening.
pmichaud authored Jun 18, 2011
4
0a93f6e @jnthn Improve object creation performance in a few hot-path places (e.g. it…
jnthn authored Sep 16, 2011
5 method new(:$key, Mu :$value) { nqp::create(self).BUILD($key, $value) }
a65c17f @moritz allow hashes to store Mu values
moritz authored Jun 30, 2011
6 method BUILD(\$key, Mu \$value) { $!key = $key; $!value = $value; self }
434bab6 @pmichaud Add Enum, Pair, .pairs method, and enum/hash flattening.
pmichaud authored Jun 18, 2011
7
c087c52 @moritz fix syntax error in previous commit, moritz--
moritz authored Jul 28, 2011
8 multi method ACCEPTS(Enum:D: Associative:D $topic) {
7129b21 @pmichaud Add some filetest operators.
pmichaud authored Jul 27, 2011
9 $topic{$.key} ~~ $.value
10 }
11
12 multi method ACCEPTS(Enum:D: Mu $topic) {
13 my $method = $.key;
14 $topic."$method"() === $.value;
15 }
e9ee086 @jnthn Enum.invert (inherited by Pair).
jnthn authored Aug 3, 2011
16
17 method invert() {
18 $.value => $.key;
19 }
7129b21 @pmichaud Add some filetest operators.
pmichaud authored Jul 27, 2011
20
c2307d4 @moritz routines that unbox to native types or access attributes need :D in t…
moritz authored Jul 28, 2011
21 method key(Enum:D:) { $!key }
22 method kv(Enum:D:) { $!key, $!value }
23 method value(Enum:D:) { $!value }
434bab6 @pmichaud Add Enum, Pair, .pairs method, and enum/hash flattening.
pmichaud authored Jun 18, 2011
24
c2307d4 @moritz routines that unbox to native types or access attributes need :D in t…
moritz authored Jul 28, 2011
25 method keys(Enum:D:) { ($!key,).list }
26 method values(Enum:D:){ ($!value,).list }
27 method pairs(Enum:D:) { (self,).list }
6970e7e @moritz values, pairs, kv
moritz authored Jul 22, 2011
28
434bab6 @pmichaud Add Enum, Pair, .pairs method, and enum/hash flattening.
pmichaud authored Jun 18, 2011
29 multi method Str(Enum:D:) { $.key ~ "\t" ~ $.value }
a02622b @pmichaud Add &infix:«=>» and Enum.perl.
pmichaud authored Jun 18, 2011
30 multi method perl(Enum:D:) { $.key.perl ~ ' => ' ~ $.value.perl }
d97997e @moritz implement .fmt in Enum and EnumMap
moritz authored Sep 13, 2011
31
32 method fmt($format = "%s\t%s") {
33 sprintf($format, $.key, $.value);
34 }
9e7a62e @jnthn Add Enum.at_key.
jnthn authored Sep 29, 2011
35
36 method at_key($key) {
37 $key eq $!key ?? $!value !! Mu
38 }
434bab6 @pmichaud Add Enum, Pair, .pairs method, and enum/hash flattening.
pmichaud authored Jun 18, 2011
39 }
40
48a44ea @pmichaud Move &infix:<eqv> and &infix:<===> candidates into their appropriate …
pmichaud authored Aug 18, 2011
41 multi sub infix:<eqv>(Enum:D $a, Enum:D $b) {
42 $a.WHAT === $b.WHAT && $a.key eqv $b.key && $a.value eqv $b.value
43 }
44
Something went wrong with that request. Please try again.