Code Duplication    Length = 17-18 lines in 2 locations

src/Arrayy.php 2 locations

@@ 3590-3606 (lines=17) @@
3587
     * @phpstan-return static<TKey,T>
3588
     * @psalm-mutation-free
3589
     */
3590
    public function indexBy($key): self
3591
    {
3592
        // init
3593
        $results = [];
3594
3595
        foreach ($this->getGenerator() as $a) {
3596
            if (\array_key_exists($key, $a) === true) {
3597
                $results[$a[$key]] = $a;
3598
            }
3599
        }
3600
3601
        return static::create(
3602
            $results,
3603
            $this->iteratorClass,
3604
            false
3605
        );
3606
    }
3607
3608
    /**
3609
     * alias: for "Arrayy->searchIndex()"
@@ 4812-4829 (lines=18) @@
4809
     * @phpstan-return static<TKey,T>
4810
     * @psalm-mutation-free
4811
     */
4812
    public function only(array $keys): self
4813
    {
4814
        $keys = \array_flip($keys);
4815
4816
        $generator = function () use ($keys): \Generator {
4817
            foreach ($this->getGenerator() as $key => $value) {
4818
                if (isset($keys[$key])) {
4819
                    yield $key => $value;
4820
                }
4821
            }
4822
        };
4823
4824
        return static::create(
4825
            $generator,
4826
            $this->iteratorClass,
4827
            false
4828
        );
4829
    }
4830
4831
    /**
4832
     * Pad array to the specified size with a given value.