| @@ 87-97 (lines=11) @@ | ||
| 84 | $this->collection = []; |
|
| 85 | } |
|
| 86 | ||
| 87 | public function map(callable $func) |
|
| 88 | { |
|
| 89 | $result = []; |
|
| 90 | ||
| 91 | foreach ($this->collection as $key => $item) { |
|
| 92 | $result[$key] = $func($item); |
|
| 93 | } |
|
| 94 | ||
| 95 | $this->clear(); |
|
| 96 | $this->collection = $result; |
|
| 97 | } |
|
| 98 | ||
| 99 | public function filter(callable $func) |
|
| 100 | { |
|
| @@ 99-111 (lines=13) @@ | ||
| 96 | $this->collection = $result; |
|
| 97 | } |
|
| 98 | ||
| 99 | public function filter(callable $func) |
|
| 100 | { |
|
| 101 | $result = []; |
|
| 102 | ||
| 103 | foreach ($this->collection as $key => $item) { |
|
| 104 | if ($func($key, $item)) { |
|
| 105 | $result[$key] = $item; |
|
| 106 | } |
|
| 107 | } |
|
| 108 | ||
| 109 | $this->clear(); |
|
| 110 | $this->collection = $result; |
|
| 111 | } |
|
| 112 | ||
| 113 | public function each(callable $func) |
|
| 114 | { |
|
| @@ 122-134 (lines=13) @@ | ||
| 119 | } |
|
| 120 | } |
|
| 121 | ||
| 122 | public function not(callable $func) |
|
| 123 | { |
|
| 124 | $result = []; |
|
| 125 | ||
| 126 | foreach ($this->collection as $key => $item) { |
|
| 127 | if (! $func($key, $item)) { |
|
| 128 | $result[$key] = $item; |
|
| 129 | } |
|
| 130 | } |
|
| 131 | ||
| 132 | $this->clear(); |
|
| 133 | $this->collection = $result; |
|
| 134 | } |
|
| 135 | ||
| 136 | public function reduce($initial, callable $func) |
|
| 137 | { |
|