@@ 260-270 (lines=11) @@ | ||
257 | /** |
|
258 | * @inheritDoc |
|
259 | */ |
|
260 | public function map(callable $callback) |
|
261 | { |
|
262 | $count = count($this); |
|
263 | $sfa = new SplFixedArray($count); |
|
264 | ||
265 | for ($i = 0; $i < $count; $i++) { |
|
266 | $sfa[$i] = $callback($this[$i], $i, $this); |
|
267 | } |
|
268 | ||
269 | return new static($sfa); |
|
270 | } |
|
271 | ||
272 | /** |
|
273 | * @inheritDoc |
|
@@ 287-301 (lines=15) @@ | ||
284 | /** |
|
285 | * @inheritDoc |
|
286 | */ |
|
287 | public function filter(callable $callback) |
|
288 | { |
|
289 | $count = count($this); |
|
290 | $sfa = new SplFixedArray($count); |
|
291 | $newCount = 0; |
|
292 | ||
293 | foreach ($this as $elem) { |
|
294 | if ($callback($elem)) { |
|
295 | $sfa[$newCount++] = $elem; |
|
296 | } |
|
297 | } |
|
298 | ||
299 | $sfa->setSize($newCount); |
|
300 | return new static($sfa); |
|
301 | } |
|
302 | ||
303 | /** |
|
304 | * @inheritDoc |