src/Primitive/Container/Container.php
public function chunk($size = 2, $preserveKeys = false)
    {
        $size = $this->getIntegerable($size);

        if ( ! is_integer($size) || $size > $this->length())
        {
            throw new BadLengthException('Chunk size is larger than container length');
        }

        $chunks = new static;

        foreach (array_chunk($this->items, $size, $this->getBoolable($preserveKeys)) as $value)
        {
            $chunks->push(new static($value));
        }

        return $chunks;
    }
public function chunk($size = 2, $preserveKeys = false)
    {
        $size = $this->getIntegerable($size);

        if ( ! is_integer($size) || $size > $this->length())
        {
            throw new BadLengthException('Chunk size is larger than container length');
        }

        $chunks = new static;

        foreach (array_chunk($this->items, $size, $this->getBoolable($preserveKeys)) as $value)
        {
            $chunks->push(new static($value));
        }

        return $chunks;
    }
Return split Container items into chunks wrapped with new Container.

@param int|IntegerContract  $size
@param bool|BooleanContract $preserveKeys
@return \im\Primitive\Container\Container
@throws \im\Primitive\Container\Exceptions\BadLengthException