| @@ 96-106 (lines=11) @@ | ||
| 93 | $this->collection = $result; |
|
| 94 | } |
|
| 95 | ||
| 96 | public function map(callable $func) |
|
| 97 | { |
|
| 98 | $result = []; |
|
| 99 | ||
| 100 | foreach ($this->collection as $key => $item) { |
|
| 101 | $result[$key] = $func($item); |
|
| 102 | } |
|
| 103 | ||
| 104 | $this->clear(); |
|
| 105 | $this->collection = $result; |
|
| 106 | } |
|
| 107 | ||
| 108 | public function filter(callable $func) |
|
| 109 | { |
|
| @@ 108-120 (lines=13) @@ | ||
| 105 | $this->collection = $result; |
|
| 106 | } |
|
| 107 | ||
| 108 | public function filter(callable $func) |
|
| 109 | { |
|
| 110 | $result = []; |
|
| 111 | ||
| 112 | foreach ($this->collection as $key => $item) { |
|
| 113 | if ($func($key, $item)) { |
|
| 114 | $result[$key] = $item; |
|
| 115 | } |
|
| 116 | } |
|
| 117 | ||
| 118 | $this->clear(); |
|
| 119 | $this->collection = $result; |
|
| 120 | } |
|
| 121 | ||
| 122 | public function each(callable $func) |
|
| 123 | { |
|
| @@ 131-143 (lines=13) @@ | ||
| 128 | } |
|
| 129 | } |
|
| 130 | ||
| 131 | public function not(callable $func) |
|
| 132 | { |
|
| 133 | $result = []; |
|
| 134 | ||
| 135 | foreach ($this->collection as $key => $item) { |
|
| 136 | if (! $func($key, $item)) { |
|
| 137 | $result[$key] = $item; |
|
| 138 | } |
|
| 139 | } |
|
| 140 | ||
| 141 | $this->clear(); |
|
| 142 | $this->collection = $result; |
|
| 143 | } |
|
| 144 | ||
| 145 | public function reduce($initial, callable $func) |
|
| 146 | { |
|