public function split($numberOfGroups) { if ($this->isEmpty()) { return new static(); } $groupSize = ceil($this->count() / $numberOfGroups); return $this->chunk($groupSize); }
public function testSplitEmptyCollection() { $collection = new Collection(); $this->assertEquals([], $collection->split(2)->map(function (Collection $chunk) { return $chunk->values()->toArray(); })->toArray()); }