Code Duplication    Length = 12-17 lines in 3 locations

src/Arrayy.php 3 locations

@@ 2267-2281 (lines=15) @@
2264
     * @psalm-return static<TKey,T>
2265
     * @psalm-mutation-free
2266
     */
2267
    public function each(\Closure $closure): self
2268
    {
2269
        // init
2270
        $array = [];
2271
2272
        foreach ($this->getGenerator() as $key => $value) {
2273
            $array[$key] = $closure($value, $key);
2274
        }
2275
2276
        return static::create(
2277
            $array,
2278
            $this->iteratorClass,
2279
            false
2280
        );
2281
    }
2282
2283
    /**
2284
     * Sets the internal iterator to the last element in the array and returns this element.
@@ 5201-5212 (lines=12) @@
5198
     * @psalm-return static<TKey,T>
5199
     * @psalm-mutation-free
5200
     */
5201
    public function reduce($callable, $initial = []): self
5202
    {
5203
        foreach ($this->getGenerator() as $key => $value) {
5204
            $initial = $callable($initial, $value, $key);
5205
        }
5206
5207
        return static::create(
5208
            $initial,
5209
            $this->iteratorClass,
5210
            false
5211
        );
5212
    }
5213
5214
    /**
5215
     * @param bool $unique
@@ 5286-5302 (lines=17) @@
5283
     * @psalm-return static<TKey,T>
5284
     * @psalm-mutation-free
5285
     */
5286
    public function reject(\Closure $closure): self
5287
    {
5288
        // init
5289
        $filtered = [];
5290
5291
        foreach ($this->getGenerator() as $key => $value) {
5292
            if (!$closure($value, $key)) {
5293
                $filtered[$key] = $value;
5294
            }
5295
        }
5296
5297
        return static::create(
5298
            $filtered,
5299
            $this->iteratorClass,
5300
            false
5301
        );
5302
    }
5303
5304
    /**
5305
     * Remove a value from the current array (optional using dot-notation).