@@ 262-270 (lines=9) @@ | ||
259 | * |
|
260 | * @return Collection |
|
261 | */ |
|
262 | public function map(\Closure $closure, array $context = array(), $static = true) |
|
263 | { |
|
264 | $collection = $static ? new static() : new self(); |
|
265 | foreach ($this as $key => $value) { |
|
266 | $collection->add($key, $closure($key, $value, $context)); |
|
267 | } |
|
268 | ||
269 | return $collection; |
|
270 | } |
|
271 | ||
272 | /** |
|
273 | * Iterates over each key value pair in the collection passing them to the Closure. If the Closure function returns |
|
@@ 282-292 (lines=11) @@ | ||
279 | * |
|
280 | * @return Collection |
|
281 | */ |
|
282 | public function filter(\Closure $closure, $static = true) |
|
283 | { |
|
284 | $collection = ($static) ? new static() : new self(); |
|
285 | foreach ($this->data as $key => $value) { |
|
286 | if ($closure($key, $value)) { |
|
287 | $collection->add($key, $value); |
|
288 | } |
|
289 | } |
|
290 | ||
291 | return $collection; |
|
292 | } |
|
293 | ||
294 | public function offsetExists($offset) |
|
295 | { |