Code Duplication    Length = 12-24 lines in 2 locations

src/Ds/Map.php 1 location

@@ 285-296 (lines=12) @@
282
     *
283
     * @return Map
284
     */
285
    public function filter(callable $callback = null): Map
286
    {
287
        $filtered = new self();
288
289
        foreach ($this as $key => $value) {
290
            if ($callback ? $callback($key, $value) : $value) {
291
                $filtered->put($key, $value);
292
            }
293
        }
294
295
        return $filtered;
296
    }
297
298
    /**
299
     * Returns the value associated with a key, or an optional default if the

src/Ds/Set.php 1 location

@@ 207-230 (lines=24) @@
204
     *
205
     * @return Set
206
     */
207
    public function filter(callable $callback = null): Set
208
    {
209
        $filtered = new Set();
210
211
        if ($callback) {
212
213
            //
214
            foreach ($this as $value) {
215
                if ($callback($value)) {
216
                    $filtered->add($value);
217
                }
218
            }
219
        } else {
220
221
            //
222
            foreach ($this as $value) {
223
                if ($value) {
224
                    $filtered->add($value);
225
                }
226
            }
227
        }
228
229
        return $filtered;
230
    }
231
232
    /**
233
     * Returns the first value in the set.