@@ 173-184 (lines=12) @@ | ||
170 | * |
|
171 | * @return Set |
|
172 | */ |
|
173 | public function filter(callable $predicate = null): Set |
|
174 | { |
|
175 | $filtered = new Set(); |
|
176 | ||
177 | foreach ($this as $value) { |
|
178 | if ($predicate ? $predicate($value) : $value) { |
|
179 | $filtered->add($value); |
|
180 | } |
|
181 | } |
|
182 | ||
183 | return $filtered; |
|
184 | } |
|
185 | ||
186 | /** |
|
187 | * Returns the first value in the set. |
@@ 264-275 (lines=12) @@ | ||
261 | * |
|
262 | * @return Map |
|
263 | */ |
|
264 | public function filter(callable $predicate = null): Map |
|
265 | { |
|
266 | $filtered = new self(); |
|
267 | ||
268 | foreach ($this as $key => $value) { |
|
269 | if ($predicate ? $predicate($key, $value) : $value) { |
|
270 | $filtered->put($key, $value); |
|
271 | } |
|
272 | } |
|
273 | ||
274 | return $filtered; |
|
275 | } |
|
276 | ||
277 | /** |
|
278 | * Returns the value associated with a key, or an optional default if the |