public function chunk(ActiveQueryInterface $query, $size, callable $callback)
    {
        $pageNumber = 1;
        $records = $this->paginateRecords($query, $pageNumber, $size)->all();
        $results = [];

        while (count($records) > 0) {
            // On each chunk, pass the records to the callback and then let the
            // developer take care of everything within the callback. This allows to
            // keep the memory low when looping through large result sets.
            $callableResults = $callback($records);

            if ($callableResults === false) {
                break;
            }

            // If the results of the given callable function were an array
            // merge them into the result array which is returned at the end of the chunking.
            if (\is_array($callableResults)) {
                $results = \array_merge($results, $callableResults);
            }

            $pageNumber++;
            $records = $this->paginateRecords($query, $pageNumber, $size)->all();
        }

        return $results;
    }