|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\Immutable; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Collection of elements is a determined order (maybe with duplicates) |
|
8
|
|
|
*/ |
|
9
|
|
|
interface SequenceInterface extends SizeableInterface, PrimitiveInterface, \Countable, \Iterator, \ArrayAccess |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Return the element at the given index |
|
13
|
|
|
* |
|
14
|
|
|
* @param int $index |
|
15
|
|
|
* |
|
16
|
|
|
* @throws OutOfBoundException |
|
17
|
|
|
* |
|
18
|
|
|
* @return mixed |
|
19
|
|
|
*/ |
|
20
|
|
|
public function get(int $index); |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Return the diff between this sequence and another |
|
24
|
|
|
* |
|
25
|
|
|
* @param self $seq |
|
26
|
|
|
* |
|
27
|
|
|
* @return self |
|
28
|
|
|
*/ |
|
29
|
|
|
public function diff(self $seq): self; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Remove all duplicates from the sequence |
|
33
|
|
|
* |
|
34
|
|
|
* @return self |
|
35
|
|
|
*/ |
|
36
|
|
|
public function distinct(): self; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Remove the n first elements |
|
40
|
|
|
* |
|
41
|
|
|
* @param int $size |
|
42
|
|
|
* |
|
43
|
|
|
* @return self |
|
44
|
|
|
*/ |
|
45
|
|
|
public function drop(int $size): self; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Remove the n last elements |
|
49
|
|
|
* |
|
50
|
|
|
* @param int $size |
|
51
|
|
|
* |
|
52
|
|
|
* @return self |
|
53
|
|
|
*/ |
|
54
|
|
|
public function dropEnd(int $size): self; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Check if the two sequences are equal |
|
58
|
|
|
* |
|
59
|
|
|
* @param self $seq |
|
60
|
|
|
* |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
63
|
|
|
public function equals(self $seq): bool; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Return all elements that satisfy the given predicate |
|
67
|
|
|
* |
|
68
|
|
|
* @param \Closure $predicate |
|
69
|
|
|
* |
|
70
|
|
|
* @return self |
|
71
|
|
|
*/ |
|
72
|
|
|
public function filter(\Closure $predicate): self; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Apply the given function to all elements of the sequence |
|
76
|
|
|
* |
|
77
|
|
|
* @param \Closure $function |
|
78
|
|
|
* |
|
79
|
|
|
* @return self |
|
80
|
|
|
*/ |
|
81
|
|
|
public function foreach(\Closure $function): self; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Return a new map of pairs grouped by keys determined with the given |
|
85
|
|
|
* discriminator function |
|
86
|
|
|
* |
|
87
|
|
|
* @param \Closure $discriminator |
|
88
|
|
|
* |
|
89
|
|
|
* @return MapInterface |
|
90
|
|
|
*/ |
|
91
|
|
|
public function groupBy(\Closure $discriminator): MapInterface; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Return the first element |
|
95
|
|
|
* |
|
96
|
|
|
* @return mixed |
|
97
|
|
|
*/ |
|
98
|
|
|
public function first(); |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Return the last element |
|
102
|
|
|
* |
|
103
|
|
|
* @return mixed |
|
104
|
|
|
*/ |
|
105
|
|
|
public function last(); |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Check if the sequence contains the given element |
|
109
|
|
|
* |
|
110
|
|
|
* @param mixed $element |
|
111
|
|
|
* |
|
112
|
|
|
* @return bool |
|
113
|
|
|
*/ |
|
114
|
|
|
public function contains($element): bool; |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Return the index for the given element |
|
118
|
|
|
* |
|
119
|
|
|
* @param mixed $element |
|
120
|
|
|
* |
|
121
|
|
|
* @throws ElementNotFoundException |
|
122
|
|
|
* |
|
123
|
|
|
* @return int |
|
124
|
|
|
*/ |
|
125
|
|
|
public function indexOf($element): int; |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Return the list of indices |
|
129
|
|
|
* |
|
130
|
|
|
* @return self |
|
131
|
|
|
*/ |
|
132
|
|
|
public function indices(): self; |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Return a new sequence by applying the given function to all elements |
|
136
|
|
|
* |
|
137
|
|
|
* @param \Closure $function |
|
138
|
|
|
* |
|
139
|
|
|
* @return self |
|
140
|
|
|
*/ |
|
141
|
|
|
public function map(\Closure $function): self; |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Pad the sequence to a defined size with the given element |
|
145
|
|
|
* |
|
146
|
|
|
* @param int $size |
|
147
|
|
|
* @param mixed $element |
|
148
|
|
|
* |
|
149
|
|
|
* @return self |
|
150
|
|
|
*/ |
|
151
|
|
|
public function pad(int $size, $element): self; |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Return a sequence of 2 sequences partitioned according to the given predicate |
|
155
|
|
|
* |
|
156
|
|
|
* @param \Closure $predicate |
|
157
|
|
|
* |
|
158
|
|
|
* @return self[self] |
|
|
|
|
|
|
159
|
|
|
*/ |
|
160
|
|
|
public function partition(\Closure $predicate): self; |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Slice the sequence |
|
164
|
|
|
* |
|
165
|
|
|
* @param int $from |
|
166
|
|
|
* @param int $until |
|
167
|
|
|
* |
|
168
|
|
|
* @return self |
|
169
|
|
|
*/ |
|
170
|
|
|
public function slice(int $from, int $until): self; |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Split the sequence in a sequence of 2 sequences splitted at the given position |
|
174
|
|
|
* |
|
175
|
|
|
* @param int $position |
|
176
|
|
|
* |
|
177
|
|
|
* @throws OutOfBoundException |
|
178
|
|
|
* |
|
179
|
|
|
* @return self[self] |
|
|
|
|
|
|
180
|
|
|
*/ |
|
181
|
|
|
public function splitAt(int $position): self; |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Return a sequence with the n first elements |
|
185
|
|
|
* |
|
186
|
|
|
* @param int $size |
|
187
|
|
|
* |
|
188
|
|
|
* @return self |
|
189
|
|
|
*/ |
|
190
|
|
|
public function take(int $size): self; |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Return a sequence with the n last elements |
|
194
|
|
|
* |
|
195
|
|
|
* @param int $size |
|
196
|
|
|
* |
|
197
|
|
|
* @return self |
|
198
|
|
|
*/ |
|
199
|
|
|
public function takeEnd(int $size): self; |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* Append the given sequence to the current one |
|
203
|
|
|
* |
|
204
|
|
|
* @param self $seq |
|
205
|
|
|
* |
|
206
|
|
|
* @return self |
|
207
|
|
|
*/ |
|
208
|
|
|
public function append(self $seq): self; |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Return a sequence with all elements from the current one that exist |
|
212
|
|
|
* in the given one |
|
213
|
|
|
* |
|
214
|
|
|
* @param self $seq |
|
215
|
|
|
* |
|
216
|
|
|
* @return self |
|
217
|
|
|
*/ |
|
218
|
|
|
public function intersect(self $seq): self; |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* Concatenate all elements with the given separator |
|
222
|
|
|
* |
|
223
|
|
|
* @param string $separator |
|
224
|
|
|
* |
|
225
|
|
|
* @return StringPrimitive |
|
226
|
|
|
*/ |
|
227
|
|
|
public function join(string $separator): StringPrimitive; |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Add the given element at the end of the sequence |
|
231
|
|
|
* |
|
232
|
|
|
* @param mixed $element |
|
233
|
|
|
* |
|
234
|
|
|
* @return self |
|
235
|
|
|
*/ |
|
236
|
|
|
public function add($element): self; |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* Sort the sequence in a different order |
|
240
|
|
|
* |
|
241
|
|
|
* @param \Closure $function |
|
242
|
|
|
* |
|
243
|
|
|
* @return self |
|
244
|
|
|
*/ |
|
245
|
|
|
public function sort(\Closure $function): self; |
|
246
|
|
|
} |
|
247
|
|
|
|
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.