Code Duplication    Length = 12-17 lines in 3 locations

src/Arrayy.php 3 locations

@@ 2313-2327 (lines=15) @@
2310
     * @phpstan-return static<TKey,T>
2311
     * @psalm-mutation-free
2312
     */
2313
    public function each(\Closure $closure): self
2314
    {
2315
        // init
2316
        $array = [];
2317
2318
        foreach ($this->getGenerator() as $key => $value) {
2319
            $array[$key] = $closure($value, $key);
2320
        }
2321
2322
        return static::create(
2323
            $array,
2324
            $this->iteratorClass,
2325
            false
2326
        );
2327
    }
2328
2329
    /**
2330
     * Sets the internal iterator to the last element in the array and returns this element.
@@ 5315-5326 (lines=12) @@
5312
     * @phpstan-return static<TKey,T2>
5313
     * @psalm-mutation-free
5314
     */
5315
    public function reduce($callable, $initial = []): self
5316
    {
5317
        foreach ($this->getGenerator() as $key => $value) {
5318
            $initial = $callable($initial, $value, $key);
5319
        }
5320
5321
        return static::create(
5322
            $initial,
5323
            $this->iteratorClass,
5324
            false
5325
        );
5326
    }
5327
5328
    /**
5329
     * @param bool $unique
@@ 5401-5417 (lines=17) @@
5398
     * @phpstan-return static<TKey,T>
5399
     * @psalm-mutation-free
5400
     */
5401
    public function reject(\Closure $closure): self
5402
    {
5403
        // init
5404
        $filtered = [];
5405
5406
        foreach ($this->getGenerator() as $key => $value) {
5407
            if (!$closure($value, $key)) {
5408
                $filtered[$key] = $value;
5409
            }
5410
        }
5411
5412
        return static::create(
5413
            $filtered,
5414
            $this->iteratorClass,
5415
            false
5416
        );
5417
    }
5418
5419
    /**
5420
     * Remove a value from the current array (optional using dot-notation).