Code Duplication    Length = 17-18 lines in 2 locations

src/Arrayy.php 2 locations

@@ 3546-3562 (lines=17) @@
3543
     * @phpstan-return static<TKey,T>
3544
     * @psalm-mutation-free
3545
     */
3546
    public function indexBy($key): self
3547
    {
3548
        // init
3549
        $results = [];
3550
3551
        foreach ($this->getGenerator() as $a) {
3552
            if (\array_key_exists($key, $a) === true) {
3553
                $results[$a[$key]] = $a;
3554
            }
3555
        }
3556
3557
        return static::create(
3558
            $results,
3559
            $this->iteratorClass,
3560
            false
3561
        );
3562
    }
3563
3564
    /**
3565
     * alias: for "Arrayy->searchIndex()"
@@ 4760-4777 (lines=18) @@
4757
     * @phpstan-return static<TKey,T>
4758
     * @psalm-mutation-free
4759
     */
4760
    public function only(array $keys): self
4761
    {
4762
        $keys = \array_flip($keys);
4763
4764
        $generator = function () use ($keys): \Generator {
4765
            foreach ($this->getGenerator() as $key => $value) {
4766
                if (isset($keys[$key])) {
4767
                    yield $key => $value;
4768
                }
4769
            }
4770
        };
4771
4772
        return static::create(
4773
            $generator,
4774
            $this->iteratorClass,
4775
            false
4776
        );
4777
    }
4778
4779
    /**
4780
     * Pad array to the specified size with a given value.