-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotes.txt
154 lines (111 loc) · 2.79 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
DEVELOPMENT NOTES
Name:
Pair::Data
Pair::Real
Pair::Object
Pair::Mutable
Pair::Special
Pair::More
Pair::Super
Pair::Simple
Pair::Tiny
Pair::ReadWrite, Pair::RW
Pair::Again
Data::Pair
Tuple::Pair
NonCore::Pair
Pair::
PairX::
Paired::
Pairing::
Pairable::
Duo::
Par::
Paire::
Couple::
Repair::
Despair::
Junctions
(k → a|b|c) => (k → a) | (k → b) | (k → c)
(k → a&b&c) => (k → a) & (k → b) & (k → c)
Operator
k => v
k =» v
k ≡> v
k ≡» v
k → v
k ↠ v
k ↦ v
k ⇒ v
k ⇨ v
k ⇾ v
k ⊳ v
Core Perl 6 Pair class (src/core/Pair.pm6):
class Pair does Associative {
has $.key is default(Nil);
has $.value is default(Nil) is rw;
}
Alternative ways:
Both key and value as read-writable attributes.
class SomePair { # key/value of type Any
has $.key is rw;
has $.value is rw;
}
class SomePair { # key/value of type Mu
has Mu $.key is rw;
has Mu $.value is rw;
}
role Paired[::KeyType, ::ValueType] {
has KeyType $.key is rw;
has ValueType $.value is rw;
}
role Paired[::KeyType = SomeType, ::ValueType = SomeType] {...} # default types
class SomePair does Paired[Mu, Mu ] {...}
class SomePair does Paired[Any, Any ] {...}
class SomePair does Paired[Cool, Cool] {...}
class SomePair does Paired[Str, Any ] {...} # string key
class SomePair does Paired[Str, Str ] {...} # strictly stringy
class SomePair::Super is SomePair does Positional does Associative {...}
class SomePair::Positional is SomePair does Positional {...}
class SomePair::Associative is SomePair does Associative {...}
roles Positional and Associative
method AT-POS
method EXISTS-POS
method AT-KEY
method EXISTS-KEY
method STORE
Associative:
Getting
$value = $pair{$key};
if $key matches $pair.key, then returns $pair.value
otherwise ...
Setting
$pair{$key} = $value;
if $key matches $pair.key, then sets $pair.value to $value
otherwise ...
Positional:
Getting
$pair[0] #=> returns key
$pair[1] #=> returns value
$pair[2] #=> returns what? Nil, Any, Mu, The::Pair::Object? fail? die? warn?
Setting
$pair[0] = 'key'; # sets key
$pair[1] = 'value'; # sets value
$pair[2] = ... ; # do what? fail? die?
Method names:
mirror, mirrored
for k/v types: method is-heterogenous(--> Bool) { not self.is-homogeneous }
key-type, value-type
key-of, value-of
reversible
invertible
flippable
---
Remove role to test problems:
class Duo {
# also does Duo::Role[Any, Any];
has Any $.key is rw;
has Any $.value is rw;
multi method new($key, $value = Any) { self.new(:$key, :$value) }
method set(\k, \v) is aka<update> { ($!key, $!value) = (k, v); self }
}