|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\Immutable; |
|
5
|
|
|
|
|
6
|
|
|
interface MapInterface extends SizeableInterface, \Countable, \Iterator, \ArrayAccess |
|
7
|
|
|
{ |
|
8
|
|
|
public function __construct(string $keyType, string $valueType); |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Return the key type for this map |
|
12
|
|
|
* |
|
13
|
|
|
* @return StringPrimitive |
|
14
|
|
|
*/ |
|
15
|
|
|
public function keyType(): StringPrimitive; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Return the value type for this map |
|
19
|
|
|
* |
|
20
|
|
|
* @return StringPrimitive |
|
21
|
|
|
*/ |
|
22
|
|
|
public function valueType(): StringPrimitive; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Set a new key/value pair |
|
26
|
|
|
* |
|
27
|
|
|
* @param mixed $key |
|
28
|
|
|
* @param mixed $value |
|
29
|
|
|
* |
|
30
|
|
|
* @return self |
|
31
|
|
|
*/ |
|
32
|
|
|
public function put($key, $value): self; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Return the element with the given key |
|
36
|
|
|
* |
|
37
|
|
|
* @param mixed $key |
|
38
|
|
|
* |
|
39
|
|
|
* @throws ElementNotFoundException |
|
40
|
|
|
* |
|
41
|
|
|
* @return mixed |
|
42
|
|
|
*/ |
|
43
|
|
|
public function get($key); |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Check if there is an element for the given key |
|
47
|
|
|
* |
|
48
|
|
|
* @param mixed $key |
|
49
|
|
|
* |
|
50
|
|
|
* @return bool |
|
51
|
|
|
*/ |
|
52
|
|
|
public function contains($key): bool; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Remove the n first elements |
|
56
|
|
|
* |
|
57
|
|
|
* @param int $size |
|
58
|
|
|
* |
|
59
|
|
|
* @return self |
|
60
|
|
|
*/ |
|
61
|
|
|
public function drop(int $size): self; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Remove the n last elements |
|
65
|
|
|
* |
|
66
|
|
|
* @param int $size |
|
67
|
|
|
* |
|
68
|
|
|
* @return self |
|
69
|
|
|
*/ |
|
70
|
|
|
public function dropEnd(int $size): self; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Return an empty map given the same given type |
|
74
|
|
|
* |
|
75
|
|
|
* @return self |
|
76
|
|
|
*/ |
|
77
|
|
|
public function clear(): self; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Check if the two maps are equal |
|
81
|
|
|
* |
|
82
|
|
|
* @param self $map |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public function equals(self $map): bool; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Filter the map based on the given predicate |
|
90
|
|
|
* |
|
91
|
|
|
* @param Closure $predicate |
|
92
|
|
|
* |
|
93
|
|
|
* @return self |
|
94
|
|
|
*/ |
|
95
|
|
|
public function filter(\Closure $predicate): self; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Run the given function for each element of the map |
|
99
|
|
|
* |
|
100
|
|
|
* @param Closure $function |
|
101
|
|
|
* |
|
102
|
|
|
* @return self |
|
103
|
|
|
*/ |
|
104
|
|
|
public function foreach(\Closure $function): self; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Return a new map of pairs' sequences grouped by keys determined with the given |
|
108
|
|
|
* discriminator function |
|
109
|
|
|
* |
|
110
|
|
|
* @param Closure $discriminator |
|
111
|
|
|
* |
|
112
|
|
|
* @return self |
|
113
|
|
|
*/ |
|
114
|
|
|
public function groupBy(\Closure $discriminator): self; |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Return the first element |
|
118
|
|
|
* |
|
119
|
|
|
* @return Pair |
|
120
|
|
|
*/ |
|
121
|
|
|
public function first(): Pair; |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Return the last element |
|
125
|
|
|
* |
|
126
|
|
|
* @return Pair |
|
127
|
|
|
*/ |
|
128
|
|
|
public function last(): Pair; |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Return all keys |
|
132
|
|
|
* |
|
133
|
|
|
* @return SequenceInterface |
|
134
|
|
|
*/ |
|
135
|
|
|
public function keys(): SequenceInterface; |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Return all values |
|
139
|
|
|
* |
|
140
|
|
|
* @return SequenceInterface |
|
141
|
|
|
*/ |
|
142
|
|
|
public function values(): SequenceInterface; |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Apply the given function on all elements and return a new map |
|
146
|
|
|
* |
|
147
|
|
|
* Keys can't be modified |
|
148
|
|
|
* |
|
149
|
|
|
* @param Closure $function |
|
150
|
|
|
* |
|
151
|
|
|
* @return self |
|
152
|
|
|
*/ |
|
153
|
|
|
public function map(\Closure $function): self; |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Return a sequence with the n first elements |
|
157
|
|
|
* |
|
158
|
|
|
* @param int $size |
|
159
|
|
|
* |
|
160
|
|
|
* @return self |
|
161
|
|
|
*/ |
|
162
|
|
|
public function take(int $size): self; |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Return a sequence with the n last elements |
|
166
|
|
|
* |
|
167
|
|
|
* @param int $size |
|
168
|
|
|
* |
|
169
|
|
|
* @return self |
|
170
|
|
|
*/ |
|
171
|
|
|
public function takeEnd(int $size): self; |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Concatenate all elements with the given separator |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $separator |
|
177
|
|
|
* |
|
178
|
|
|
* @return StringPrimitive |
|
179
|
|
|
*/ |
|
180
|
|
|
public function join(string $separator): StringPrimitive; |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Remove the element with the given key |
|
184
|
|
|
* |
|
185
|
|
|
* @param mixed $key |
|
186
|
|
|
* |
|
187
|
|
|
* @return self |
|
188
|
|
|
*/ |
|
189
|
|
|
public function remove($key): self; |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Create a new map by combining both maps |
|
193
|
|
|
* |
|
194
|
|
|
* @param self $map |
|
195
|
|
|
* |
|
196
|
|
|
* @return self |
|
197
|
|
|
*/ |
|
198
|
|
|
public function merge(self $map): self; |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Return a map of 2 maps partitioned according to the given predicate |
|
202
|
|
|
* |
|
203
|
|
|
* @param \Closure $predicate |
|
204
|
|
|
* |
|
205
|
|
|
* @return self<bool, self> |
|
|
|
|
|
|
206
|
|
|
*/ |
|
207
|
|
|
public function partition(\Closure $predicate): self; |
|
208
|
|
|
} |
|
209
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.