Groupping function
@param  callable $cb Callback called when response received
@param  array $p Hash of properties (offset, limit, opts, key, col, reduce, initial)
@callback $cb ( )
@return void
2920
public function group($cb, $p = [])
    {
        $p['col'] = $this->name;
        $this->pool->group($p, $cb);
    }
804858
public function onConnected($cb)
    {
        if ($this->state === self::CONN_STATE_HANDSHAKED_ERROR) {
            $cb($this);
        } elseif ($this->state === self::CONN_STATE_HANDSHAKED_OK) {
            $cb($this);
        } else {
            if (!$this->onConnected) {
                $this->onConnected = new StackCallbacks();
            }

            $this->onConnected->push($cb);
        }
    }
206894
public function groups(callable $groupCallback = null)
    {
        $groups = $this->groups;
        uasort($groups, [ $this, 'sortItemsByPriority' ]);

        $groupCallback = (isset($groupCallback) ? $groupCallback : $this->groupCallback);

        $groups = $this->finalizeFormGroups($groups);

        $i = 1;
        foreach ($groups as $group) {
            if ($groupCallback) {
                $groupCallback($group);
            }

            $GLOBALS['widget_template'] = $group->template();

            if (!$this->selectedFormGroup() && $this->isTabbable()) {
                $group->setIsHidden(false);
                if ($i > 1) {
                    $group->setIsHidden(true);
                }
            }
            $i++;

            yield $group;

            $GLOBALS['widget_template'] = '';
        }
    }
905016
public function each($cb) {
        foreach ($this->data as $context) {
            $context = new Context($context);

            if (false === $cb($context)) {
                break;
            }
        }

        return $this;
    }
706519
public function group(array $attributes, \Closure $callback)
    {
        if (isset($attributes['middleware']) && is_string($attributes['middleware'])) {
            $attributes['middleware'] = explode('|', $attributes['middleware']);
        }

        $this->updateGroupStack($attributes);

        call_user_func($callback, $this);

        array_pop($this->groupStack);
    }
387143
public function group(array $routeOption = [], $callback)
    {
        if (isset($routeOption['namespace'])) {
            $this->namespace = '\\' . $routeOption['namespace'] . '\\';
        }

        (isset($routeOption['prefix'])) ? $this->prefix = '/' . $routeOption['prefix'] : $this->prefix = '';

        (isset($routeOption['filter'])) ? $this->filter = ['filter' => $routeOption['filter']] : $this->filter = [];

        call_user_func_array($callback, $routeOption);

        $this->prefix = '';

        $this->filter = [];
    }
16969
protected function heapSort(callable $cb)
    {
        $h = new CallbackHeap($cb);
        foreach ($this as $el) {
            $h->insert($el);
        }

        return static::fromItems($h);
    }
876282
public function findOne($p, $cb)
    {
        if (isset($p['cachekey'])) {
            $db = $this;
            $this->cache->get($p['cachekey'], function ($r) use ($db, $p, $cb) {
                if ($r->result !== null) {
                    $cb(bson_decode($r->result));
                } else {
                    unset($p['cachekey']);
                    $db->findOne($p, $cb);
                }
            });

            return;
        }
        if (!isset($p['where'])) {
            $p['where'] = [];
        }

        $this->_params($p);

        $o = [];
        $s = false;

        foreach ($p as $k => $v) {
            if (($k === 'sort') || ($k === 'hint') || ($k === 'explain') || ($k === 'snapshot')) {
                if (!$s) {
                    $s = true;
                }

                if ($k === 'sort') {
                    $o['orderby'] = $v;
                } elseif ($k === 'parse_oplog') {
                } elseif ($k === 'rp') {
                    $o['$readPreference'] = $v;
                } else {
                    $o[$k] = $v;
                }
            }
        }
        if (empty($o['orderby'])) {
            unset($o['orderby']);
        }

        if ($s) {
            $o['query'] = $p['where'];
        } else {
            $o = $p['where'];
        }
        $cb = CallbackWrapper::wrap($cb);
        if ($this->safeMode) {
            static::safeModeEnc($o);
        }
        try {
            $this->request(
                self::OP_QUERY,
                pack('V', $p['opts']) . $p['col'] . "\x00" . pack('VV', $p['offset'], -1)
                . bson_encode($o) . (isset($p['fields']) ? bson_encode($p['fields']) : ''),
                true,
                null,
                function ($conn, $reqId = null) use ($p, $cb) {
                    if (!$conn) {
                        !$cb || $cb(['$err' => 'Connection error.']);
                        return;
                    }
                    $conn->requests[$reqId] = [$p['col'], $cb, true];
                }
            );
        } catch (\MongoException $e) {
            Daemon::log('MongoClient exception: ' . $e->getMessage() . ': ' . $e->getTraceAsString());
            if ($cb !== null) {
                $cb([
                    '$err' => $e->getMessage(),
                    '$query' => $o,
                    '$fields' => isset($p['fields']) ? $p['fields'] : null
                ]);
            }
        }
    }
226940
function _LayoutCommon_groupFromOffset(offset) {
                    return offset < this._groups[0].offset ?
                        0 :
                        this._groupFrom(function (group) {
                            return offset < group.offset;
                        });
                }
1132583
public function onResponse($cb)
    {
        if ($cb === null && !$this->noSAF) {
            return;
        }
        $this->onResponse->push($cb);
        $this->checkFree();
    }
457417
private function _groupBy(&$result, $k, $v, $func)
    {
        if ($v instanceof self) {
            foreach ($v->each() as $kk => $vv) {
                $this->_groupBy($result, $kk, $vv, $func);
            }
        } else {
            $aggregate_key = call_user_func($func, $v, $k);
            $result[$aggregate_key][] = $v;
        }
    }
156038
public function uaSort($cmp_function)
    {
        if (!is_callable($cmp_function)) {
            throw new \InvalidArgumentException(
                'Callback is not callable.',
                E_USER_ERROR
            );
        }

        return uasort($this->storedData, $cmp_function);
    }
1192888
public function setnx($key, $value, $cb = null)
    {
        $this->redis->setnx($this->config->redisprefix->value . $key, $value, $cb);
    }
245649
public function addEvent($id, callable $cb)
    {
        if (!isset($this->events[$id])) {
            $this->events[$id] = [];
        }

        $this->events[$id][] = $cb;
    }
535628
function grouped(array, groups, order) {
  if (!groups) { groups = [returnFalse]; }
  var sorted = [];
  var ordered = [];
  var remaining = array.slice();
  var unmatchedPosition = groups.indexOf('unmatched');
  groups.forEach(function(criteria, index) {
    if (index === unmatchedPosition) { return; }
    var tieBreakers = [];
    if (index !== groups.length - 1) {
      tieBreakers = groups.slice(index + 1);
      if (index < unmatchedPosition) {
        tieBreakers.splice(unmatchedPosition - index - 1, 1);
      }
    }
    var spliced = splice(remaining, criteria, tieBreakers);
    var matched = spliced.matched;
    var unmatched = spliced.unmatched;
    sorted[index] = matched;
    remaining = unmatched;
  });
  if (unmatchedPosition === -1) { unmatchedPosition = sorted.length; }
  sorted[unmatchedPosition] = remaining;
  if (Array.isArray(order)) {
    order.forEach(function(position, index) {
      ordered[index] = sorted[position];
    });
  } else {
    ordered = sorted;
  }
  return ordered.reduce(function(flat, group) {
    return flat.concat(group);
  }, []);
}
554044
private function aggregate($type, $cb = null)
    {
        $data = [];

        $this->recursive(
            $this->storage,
            function ($value) use (& $data) {
                if (is_numeric($value)) {
                    $data[] = $value;
                }
            }
        );

        $r = call_user_func_array($type, $data);

        if (is_callable($cb)) {
            call_user_func_array($cb, [$r]);
        }

        return $r;
    }
338527
public function group($name, $settings = null, $callback = null)
    {
        if($this->cacheLoaded) {
            return true;
        }

        $groupName = trim($name, '/');
        $group = [];
        $group['route'] = '/' . $groupName;
        $group['before'] = $group['after'] = null;

        if (is_null($callback)) {
            $callback = $settings;
        } else {
            $group['before'][] = (!isset($settings['before']) ? null : $settings['before']);
            $group['after'][]  = (!isset($settings['after']) ? null : $settings['after']);
        }

        $groupCount = count($this->groups);
        if ($groupCount > 0) {
            $list = [];
            foreach ($this->groups as $key => $value) {
                if (is_array($value['before'])) {
                    foreach ($value['before'] as $k => $v) {
                        $list['before'][] = $v;
                    }
                    foreach ($value['after'] as $k => $v) {
                        $list['after'][] = $v;
                    }
                }
            }

            if (! is_null($group['before'])) {
                $list['before'][] = $group['before'][0];
            }

            if (! is_null($group['after'])) {
                $list['after'][] = $group['after'][0];
            }

            $group['before'] = $list['before'];
            $group['after'] = $list['after'];
        }

        $group['before'] = array_values(array_unique( (array) $group['before']));
        $group['after'] = array_values(array_unique( (array) $group['after']));

        array_push($this->groups, $group);

        if (is_object($callback)) {
            call_user_func_array($callback, [$this]);
        }

        $this->endGroup();

        return true;
    }