Code Duplication    Length = 17-18 lines in 2 locations

src/Arrayy.php 2 locations

@@ 3460-3476 (lines=17) @@
3457
     * @psalm-return static<TKey,T>
3458
     * @psalm-mutation-free
3459
     */
3460
    public function indexBy($key): self
3461
    {
3462
        // init
3463
        $results = [];
3464
3465
        foreach ($this->getGenerator() as $a) {
3466
            if (\array_key_exists($key, $a) === true) {
3467
                $results[$a[$key]] = $a;
3468
            }
3469
        }
3470
3471
        return static::create(
3472
            $results,
3473
            $this->iteratorClass,
3474
            false
3475
        );
3476
    }
3477
3478
    /**
3479
     * alias: for "Arrayy->searchIndex()"
@@ 4651-4668 (lines=18) @@
4648
     * @psalm-return static<TKey,T>
4649
     * @psalm-mutation-free
4650
     */
4651
    public function only(array $keys): self
4652
    {
4653
        $keys = \array_flip($keys);
4654
4655
        $generator = function () use ($keys): \Generator {
4656
            foreach ($this->getGenerator() as $key => $value) {
4657
                if (isset($keys[$key])) {
4658
                    yield $key => $value;
4659
                }
4660
            }
4661
        };
4662
4663
        return static::create(
4664
            $generator,
4665
            $this->iteratorClass,
4666
            false
4667
        );
4668
    }
4669
4670
    /**
4671
     * Pad array to the specified size with a given value.