Enumerable::filter()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
1
<?php
2
3
namespace Collections;
4
5
use Collections\Immutable\ImmVector;
6
7
interface Enumerable extends \IteratorAggregate
8
{
9
    /**
10
     * Returns an array converted from the current Enumerable.
11
     * @return array - an array converted from the current Enumerable.
12
     */
13
    public function toArray();
14
15
    /**
16
     * Returns an array with the values from the current Enumerable.
17
     * The keys in the current Enumerable are discarded and replaced with integer indices, starting with 0.
18
     * @return array - an array containing the values from the current Enumerable.
19
     */
20
    public function toValuesArray();
21
22
    /**
23
     * Returns a Vector converted from the current Enumerable.
24
     * Any keys in the current Enumerable are discarded and replaced with integer indices, starting with 0.
25
     * @return VectorInterface - a Vector converted from the current Enumerable.
26
     */
27
    public function toVector();
28
29
    /**
30
     * Returns an immutable vector (`ImmVector`) converted from the current `Enumerable`.
31
     * Any keys in the current `Enumerable` are discarded and replaced with integer indices, starting with 0.
32
     * @return ImmVector - an `ImmVector` converted from the current `Enumerable`.
33
     */
34
    public function toImmVector();
35
36
    /**
37
     * Returns a `Set` converted from the current `Enumerable`.
38
     * Any keys in the current `Enumerable` are discarded.
39
     * @return SetInterface - a `Set` converted from the current `Enumerable`.
40
     */
41
    public function toSet();
42
43
    /**
44
     * Returns an immutable set (`ImmSet`) converted from the current `Enumerable`.
45
     * Any keys in the current `Enumerable` are discarded.
46
     *
47
     * @return ConstSetInterface - an `ImmSet` converted from the current `Enumerable`.
48
     */
49
    public function toImmSet();
50
51
    /**
52
     * Returns an `Enumerable` containing the current `Enumerable`'s values.
53
     * Any keys are discarded.
54
     *
55
     * @return Enumerable - An `Enumerable` with the values of the current `Enumerable`.
56
     */
57
    public function values();
58
59
    /**
60
     * Executes the passed callable for each of the elements in this collection
61
     * and passes both the value and key for them on each step.
62
     * Returns the same collection for chaining.
63
     *
64
     * @param callable $fn - A callable function that will receive each of the elements
65
     * in this collection
66
     * @return Enumerable - The same `Enumerable` instance.
67
     */
68
    public function each(callable $fn);
69
70
    /**
71
     * Returns an `Enumerable` containing the values after an operation has been
72
     * applied to each value in the current `Enumerable`.
73
     *
74
     * Every value in the current `Enumerable` is affected by a call to `map()`,
75
     * unlike `filter()` where only values that meet a certain criteria are
76
     * affected.
77
     *
78
     * @param $fn - The callback containing the operation to apply to the
79
     *              `Enumerable` values.
80
     *
81
     * @return Enumerable - an `Enumerable` containing the values after a user-specified
82
     *           operation is applied.
83
     */
84
    public function map(callable $fn);
85
86
    /**
87
     * Returns an `Enumerable` containing the values of the current `Enumerable` that
88
     * meet a supplied condition.
89
     *
90
     * Only values that meet a certain criteria are affected by a call to
91
     * `filter()`, while all values are affected by a call to `map()`.
92
     *
93
     * @param $fn - The callback containing the condition to apply to the
94
     *              `Itearble` values.
95
     *
96
     * @return Enumerable - an `Enumerable` containing the values after a user-specified
97
     *           condition is applied.
98
     */
99
    public function filter(callable $fn);
100
101
    /**
102
     * Returns an `Enumerable` containing the first `n` values of the current
103
     * `Enumerable`.
104
     *
105
     * The returned `Enumerable` will always be a proper subset of the current
106
     * `Enumerable`.
107
     *
108
     * `$n` is 1-based. So the first element is 1, the second 2, etc.
109
     *
110
     * @param $size - The last element that will be included in the returned
111
     *             `Enumerable`.
112
     *
113
     * @return Enumerable - An `Enumerable that is a proper subset of the current `Enumerable`
114
     *           up to `n` elements.
115
     */
116
    public function take($size = 1);
117
118
    /**
119
     * Returns an `Enumerable` containing the values after the `n`-th element of the
120
     * current `Enumerable`.
121
     *
122
     * The returned `Enumerable` will always be a proper subset of the current
123
     * `Enumerable`.
124
     *
125
     * `$n` is 1-based. So the first element is 1, the second 2, etc.
126
     *
127
     * @param $n - The last element to be skipped; the `$n+1` element will be
128
     *             the first one in the returned `Enumerable`.
129
     *
130
     * @return Enumerable - An `Enumerable` that is a proper subset of the current `Enumerable`
131
     *           containing values after the specified `n`-th element.
132
     */
133
    public function skip($n);
134
135
    /**
136
     * Returns a subset of the current `Enumerable` starting from a given key up
137
     * to, but not including, the element at the provided length from the
138
     * starting key.
139
     *
140
     * `$start` is 0-based. `$len` is 1-based. So `slice(0, 2)` would return the
141
     * elements at key 0 and 1.
142
     *
143
     * The returned `Enumerable` will always be a proper subset of the current
144
     * `Enumerable`.
145
     *
146
     * @param $start - The starting key of the current `Enumerable` to begin the
147
     *                 returned `Enumerable`.
148
     * @param $length - The length of the returned `Enumerable`.
149
     *
150
     * @return Enumerable - An `Enumerable` that is a proper subset of the current `Enumerable`
151
     *           starting at `$start` up to but not including the element
152
     *           `$start + $len`.
153
     */
154
    public function slice($start, $length);
155
156
    /**
157
     * Returns an `Enumerable` that is the concatenation of the values of the current `Enumerable`
158
     * and the values of the provided `Traversable`.
159
     *
160
     * The values of the provided `Traversable` is concatenated to the end of the current `Enumerable`
161
     * to produce the returned `Enumerable`.
162
     *
163
     * @param \Traversable|array $traversable - The `Traversable` to concatenate to the current `Enumerable`.
164
     * @return Enumerable - The concatenated `Enumerable`.
165
     */
166
    public function concat($traversable);
167
168
    /**
169
     * Returns the first value in the current `Enumerable`.
170
     *
171
     * @return mixed - The first value in the current `Enumerable`, or `null` if the
172
     *           current `Enumerable` is empty.
173
     */
174
    public function first();
175
176
    /**
177
     * Returns the last value in the current `Enumerable`.
178
     *
179
     * @return mixed - The last value in the current `Enumerable`, or `null` if the
180
     *           current `Enumerable` is empty.
181
     */
182
    public function last();
183
184
    /**
185
     * Returns a `ConstVector` where each element is a `Pair` that combines the
186
     * element of the current `ConstVector` and the provided `Traversable`.
187
     *
188
     * If the number of elements of the `Enumerable` are not equal to the
189
     * number of elements in the `Traversable`, then only the combined elements
190
     * up to and including the final element of the one with the least number of
191
     * elements is included.
192
     *
193
     * @param $traversable - The `Traversable` to use to combine with the
194
     *                       elements of this `Enumerable`.
195
     *
196
     * @return - The `Enumerable` that combines the values of the current
0 ignored issues
show
Documentation introduced by
The doc-type - could not be parsed: Unknown type name "-" at position 0. (view supported doc-types)

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.

Loading history...
197
     *           `Enumerable` with the provided `Traversable`.
198
     */
199
    public function zip($traversable);
200
201
    /**
202
     * Groups the collection based on a given criteria
203
     * @param $callback
204
     * @return Enumerable
205
     */
206
    public function groupBy($callback);
207
208
    /**
209
     * Indexes the collection based on a given criteria
210
     * @param $callback
211
     * @return Enumerable
212
     */
213
    public function indexBy($callback);
214
215
    /**
216
     * Verifies if an element exists in the collection for a given criteria
217
     * @param callable $fn
218
     * @return Enumerable
219
     */
220
    public function exists(callable $fn);
221
222
    /**
223
     * Flatten the collection into one dimension
224
     * @return Enumerable
225
     */
226
    public function concatAll();
227
}
228