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