/** * @param int $size * @return SequenceInterface<SetInterface<A>> */ function sliding($size) { if ($size <= 0) { throw new \InvalidArgumentException(sprintf('The number must be greater than 0, but got %d.', $size)); } $slices = new Sequence(); $offset = 0; while ($offset < $this->length()) { $slices->add($this->createNew(array_slice($this->elements, $offset, $size))); $offset += $size; } return $slices; }
protected function setUp() { $this->seq = new Sequence(); $this->seq->addAll([0, $this->a = new \stdClass(), $this->b = new \stdClass(), 0]); }