| @@ 6268-6289 (lines=22) @@ | ||
| 6265 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 6266 | { |
|
| 6267 | if ($keepKeys) { |
|
| 6268 | $generator = function () use ($numberOfPieces) { |
|
| 6269 | $carry = []; |
|
| 6270 | $i = 1; |
|
| 6271 | foreach ($this->getGenerator() as $key => $value) { |
|
| 6272 | $carry[$key] = $value; |
|
| 6273 | ||
| 6274 | if ($i % $numberOfPieces !== 0) { |
|
| 6275 | ++$i; |
|
| 6276 | ||
| 6277 | continue; |
|
| 6278 | } |
|
| 6279 | ||
| 6280 | yield $carry; |
|
| 6281 | ||
| 6282 | $carry = []; |
|
| 6283 | $i = 1; |
|
| 6284 | } |
|
| 6285 | ||
| 6286 | if ([] !== $carry) { |
|
| 6287 | yield $carry; |
|
| 6288 | } |
|
| 6289 | }; |
|
| 6290 | } else { |
|
| 6291 | $generator = function () use ($numberOfPieces) { |
|
| 6292 | $carry = []; |
|
| @@ 6291-6312 (lines=22) @@ | ||
| 6288 | } |
|
| 6289 | }; |
|
| 6290 | } else { |
|
| 6291 | $generator = function () use ($numberOfPieces) { |
|
| 6292 | $carry = []; |
|
| 6293 | $i = 1; |
|
| 6294 | foreach ($this->getGenerator() as $key => $value) { |
|
| 6295 | $carry[] = $value; |
|
| 6296 | ||
| 6297 | if ($i % $numberOfPieces !== 0) { |
|
| 6298 | ++$i; |
|
| 6299 | ||
| 6300 | continue; |
|
| 6301 | } |
|
| 6302 | ||
| 6303 | yield $carry; |
|
| 6304 | ||
| 6305 | $carry = []; |
|
| 6306 | $i = 1; |
|
| 6307 | } |
|
| 6308 | ||
| 6309 | if ([] !== $carry) { |
|
| 6310 | yield $carry; |
|
| 6311 | } |
|
| 6312 | }; |
|
| 6313 | } |
|
| 6314 | ||
| 6315 | return static::create( |
|