| @@ 236-243 (lines=8) @@ | ||
| 233 | /** |
|
| 234 | * @return int|float |
|
| 235 | */ |
|
| 236 | public function sum() |
|
| 237 | { |
|
| 238 | $ops = $this->ops; |
|
| 239 | $before = '$_result = 0;'; |
|
| 240 | $ops[] = ' $_result += $_;'; |
|
| 241 | ||
| 242 | return self::evaluate($this->seed, $this->vars, $this->compile($ops), $before, ''); |
|
| 243 | } |
|
| 244 | ||
| 245 | /** |
|
| 246 | * @return int|float |
|
| @@ 248-255 (lines=8) @@ | ||
| 245 | /** |
|
| 246 | * @return int|float |
|
| 247 | */ |
|
| 248 | public function product() |
|
| 249 | { |
|
| 250 | $ops = $this->ops; |
|
| 251 | $before = '$_result = 1;'; |
|
| 252 | $ops[] = ' $_result *= $_;'; |
|
| 253 | ||
| 254 | return self::evaluate($this->seed, $this->vars, $this->compile($ops), $before, ''); |
|
| 255 | } |
|
| 256 | ||
| 257 | /** |
|
| 258 | * @return \Spindle\Collection (new instance) |
|
| @@ 290-302 (lines=13) @@ | ||
| 287 | /** |
|
| 288 | * @return \Generator |
|
| 289 | */ |
|
| 290 | public function getIterator() |
|
| 291 | { |
|
| 292 | $ops = $this->ops; |
|
| 293 | $ops[] = 'yield $_key => $_;'; |
|
| 294 | $gen = self::evaluate( |
|
| 295 | $this->seed, |
|
| 296 | $this->vars, |
|
| 297 | $this->compile($ops), |
|
| 298 | '$_result = static function() use($_seed){', |
|
| 299 | '};' |
|
| 300 | ); |
|
| 301 | return $gen(); |
|
| 302 | } |
|
| 303 | ||
| 304 | /** |
|
| 305 | * @return array |
|