Chunk the results of the query.

@param  int $count
@param  callable $callback
@return  bool
514487
public function chunk( $count, callable $callback )
	{
		$results = $this->forPage( $page = 1, $count )->get();

		while ( count( $results ) > 0 )
		{
			// On each chunk result set, we will pass them to the callback and then let the
			// developer take care of everything within the callback, which allows us to
			// keep the memory low for spinning through large result sets for working.
			if ( call_user_func( $callback, $results ) === false )
			{
				return false;
			}

			$page++;

			$results = $this->forPage( $page, $count )->get();
		}

		return true;
	}
364126
public function each( callable $callback, $count = 1000 )
	{
		if ( is_null( $this->query->orders ) && is_null( $this->query->unionOrders ) )
		{
			$this->orderBy( $this->model->getQualifiedKeyName(), 'asc' );
		}

		return $this->chunk( $count, function ( $results ) use ( $callback )
		{
			foreach ( $results as $key => $value )
			{
				if ( $callback( $value, $key ) === false )
				{
					return false;
				}
			}
		} );
	}
955822
function _count(self, usingSkipAndLimit, callback) {
    if (typeof callback !== 'function') throw new Error("callback is not a function!")
    var query = { count: self.collection.name }
    if (self.criteria) {
        query.query = self.criteria
    }
    if (usingSkipAndLimit) {
        query.skip = self._skip || 0
        query.limit = self._limit
    }
    self.db.runCommand(query, safetyNet(callback, function(result) {
        callback(null, result.n)
    }))
}
538594
public function slowlogGet($count = null) {
        $payload = ['slowlog', 'get'];

        if ($count !== null) {
            $payload[] = $count;
        }

        return $this->send($payload);
    }
774682
public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', $callback = null)
	{
		$relation = $this->getHasRelationQuery($relation);

		$query = $relation->getRelationCountQuery($relation->getRelated()->newQuery(), $this);

		if ($callback) call_user_func($callback, $query);

		return $this->addHasWhere($query, $relation, $operator, $count, $boolean);
	}
1289792
protected function paginateCustom(callable $callback, $limit = Pagination::DEFAULT_LIMIT)
    {
        $this->response->clear();

        return (new Pagination)->paginateOver($callback)->take($limit);
    }
900860
public function transaction($callback)
    {
        if (!is_callable($callback, false)) {
            throw new ConnectionException('Callback should be either closure or object-method array format');
        }
        
        $this->start();
        
        try {
            $result = call_user_func_array($callback, [$this]);
            $this->commit();
            
            return $result;
        } catch (\Exception $exception) {
            $this->rollback();
            throw $exception;
        }
    }
1331846
public function each( callable $callback, $count = 1000 )
	{
		if ( is_null( $this->orders ) && is_null( $this->unionOrders ) )
			throw new RuntimeException( 'You must specify an orderBy clause when using the "each" function.' );

		return $this->chunk( $count, function ( $results ) use ( $callback )
		{
			foreach ( $results as $key => $value )
				if ( $callback( $value, $key ) === false )
					return false;
		} );
	}
337603
public function sort(Closure $callback = null): CollectionInterface
    {
        $array = $this->toArray();

        if (is_null($callback)) {
            sort($array);
        } else {
            usort(
                $array,
                $callback
            );
        }

        return static::make($array);
    }
1278182
public function average($callback = null)
    {
        if ($count = $this->count()) {
            return $this->sum($callback) / $count;
        }
    }
615873
static public function listSum($list, $field,$callback = null)
    {
        $sum = 0;
        foreach ($list as $row) {
            if ($callback instanceof \Closure) {
                if ($callback($row) === true) {
                    $sum += $row[$field];
                }
            }else {
                $sum += $row[$field];
            }
        }
        return $sum;
    }
1344309
public function chunk($count, callable $callback)
	{
		$this->query->addSelect($this->getSelectColumns());

		return $this->query->chunk($count, function ($results) use ($callback) {
			$this->hydratePivotRelation($results->all());

			return $callback($results);
		});
	}
810607
protected function withFreshQueryLog( $callback ) {
		$loggingQueries = $this->loggingQueries;

		// First we will back up the value of the logging queries property and then
		// we'll be ready to run callbacks. This query log will also get cleared
		// so we will have a new log of all the queries that are executed now.
		$this->enableQueryLog();

		$this->getLogger()->flushQueryLog();

		// Now we'll execute this callback and capture the result. Once it has been
		// executed we will restore the value of query logging and give back the
		// value of the callback so the original callers can have the results.
		$result = $callback();

		$this->loggingQueries = $loggingQueries;

		return $result;
	}
1256026
public function getSql($count = false){
        if ($count){
            $select = 'count(*)';
        }else{
            $select = $this->voDatum->getSelect();
        }
        $sql = "select $select from $this->dbName ";
        $params = array();
        foreach ($this->joins as $k => $v){
            list($joinSql, $ps) = $v;
            $sql .= $joinSql;
            foreach ($ps as $p)
                $params[] = $p;
        }

        $where = $this->where->getString();
        if ($where)
            $sql .= ' where ' . $where;
        if (!$count)
            $sql .= $this->getOrder();
        if (is_numeric($this->limit))
            $sql .= " limit $this->limit ";
        if (is_numeric($this->offset))
            $sql .= " offset $this->offset ";

        foreach ($this->where->getParams() as $p)
            $params[] = $p;
        return array($sql, $params);
    }
571643
public function reduce(callable $callback, $init = null) {
		return array_reduce(iterator_to_array($this->getIterator()), $callback, $init);
	}
37289
public function has($relation, $operator = '>=', $count = 1, $boolean = 'and', Closure $callback = null)
    {
        if (strpos($relation, '.') !== false) {
            return $this->hasNested($relation, $operator, $count, $boolean, $callback);
        }

        $relation = $this->getHasRelationQuery($relation);

        $query = $relation->getRelationCountQuery($relation->getRelated()->newQuery(), $this);

        if ($callback) call_user_func($callback, $query);

        return $this->addHasWhere($query, $relation, $operator, $count, $boolean);
    }
529735
private static function getNumPages(int $limit, int $count): int
    {
        return (int) ceil($count / $limit);
    }