Code Duplication    Length = 12-17 lines in 3 locations

src/Arrayy.php 3 locations

@@ 2331-2345 (lines=15) @@
2328
     * @phpstan-return static<TKey,T>
2329
     * @psalm-mutation-free
2330
     */
2331
    public function each(\Closure $closure): self
2332
    {
2333
        // init
2334
        $array = [];
2335
2336
        foreach ($this->getGenerator() as $key => $value) {
2337
            $array[$key] = $closure($value, $key);
2338
        }
2339
2340
        return static::create(
2341
            $array,
2342
            $this->iteratorClass,
2343
            false
2344
        );
2345
    }
2346
2347
    /**
2348
     * Sets the internal iterator to the last element in the array and returns this element.
@@ 5353-5364 (lines=12) @@
5350
     * @phpstan-return static<TKey,T2>
5351
     * @psalm-mutation-free
5352
     */
5353
    public function reduce($callable, $initial = []): self
5354
    {
5355
        foreach ($this->getGenerator() as $key => $value) {
5356
            $initial = $callable($initial, $value, $key);
5357
        }
5358
5359
        return static::create(
5360
            $initial,
5361
            $this->iteratorClass,
5362
            false
5363
        );
5364
    }
5365
5366
    /**
5367
     * @param bool $unique
@@ 5439-5455 (lines=17) @@
5436
     * @phpstan-return static<TKey,T>
5437
     * @psalm-mutation-free
5438
     */
5439
    public function reject(\Closure $closure): self
5440
    {
5441
        // init
5442
        $filtered = [];
5443
5444
        foreach ($this->getGenerator() as $key => $value) {
5445
            if (!$closure($value, $key)) {
5446
                $filtered[$key] = $value;
5447
            }
5448
        }
5449
5450
        return static::create(
5451
            $filtered,
5452
            $this->iteratorClass,
5453
            false
5454
        );
5455
    }
5456
5457
    /**
5458
     * Remove a value from the current array (optional using dot-notation).