@@ 177-188 (lines=12) @@ | ||
174 | * |
|
175 | * @return Set |
|
176 | */ |
|
177 | public function filter(callable $predicate = null): Set |
|
178 | { |
|
179 | $filtered = new self(); |
|
180 | ||
181 | foreach ($this as $value) { |
|
182 | if ($predicate ? $predicate($value) : $value) { |
|
183 | $filtered->add($value); |
|
184 | } |
|
185 | } |
|
186 | ||
187 | return $filtered; |
|
188 | } |
|
189 | ||
190 | /** |
|
191 | * Returns the first value in the set. |
@@ 276-287 (lines=12) @@ | ||
273 | * |
|
274 | * @return Map |
|
275 | */ |
|
276 | public function filter(callable $predicate = null): Map |
|
277 | { |
|
278 | $filtered = new self(); |
|
279 | ||
280 | foreach ($this as $key => $value) { |
|
281 | if ($predicate ? $predicate($key, $value) : $value) { |
|
282 | $filtered->put($key, $value); |
|
283 | } |
|
284 | } |
|
285 | ||
286 | return $filtered; |
|
287 | } |
|
288 | ||
289 | /** |
|
290 | * Returns the value associated with a key, or an optional default if the |