Break datastore into smaller group by specific column value

@param string   $key  The key column used to break datastore into groups
@param function $func Anonymous function to be called when a group is form

@return null
350736
public function breakGroup($key,$func)
    {
        $data = array();
        $start = 0;
        foreach ($this->rows as $i=>$row) {
            if (!isset($oldValue)) {
                $oldValue = $row[$key];
            }

            if ($row[$key]==$oldValue) {
                $oldValue = $row[$key];
                array_push($data, $row);
            } else {
                $func(new DataStore($data, $this->metaData), $start);
                $start = $i;
                $data = array($row);
                $oldValue = $row[$key];
            }
        }
        $func(new DataStore($data, $this->metaData), $start);
    }
685017
private function setSaltKey($key)
    {
        $this->setKey($key);

        if (!function_exists('mcrypt_create_iv')) {
            throw new \BadFunctionCallException('Mcrypt extension library not loaded');
        }

        $this->iv = mcrypt_create_iv(32);
    }
1371351
public function remove($key)
    {
        if (isset($_SESSION[$this->name][$key])) {
            $value = $_SESSION[$this->name][$key];
            unset($_SESSION[$this->name][$key]);
            return $value;
        }

        return null;
    }
47067
public function reduce(callable $func = null, $initial = null)
    {
        if (null === $func) {
            return parent::reduce(static function ($carry, $item) {
                $carry += $item;

                return $carry;
            }, $initial ?? 0);
        }

        return parent::reduce($func, $initial);
    }
798206
public function add($func)
    {
        ValidationException::assert(
            function () use ($func) {
                return !is_callable($func);
            },
            'function is not callable'
        );
        $this->func[] = $func;
        return $this;
    }
920533
public static function call($key, callable $func)
    {
        $trace = debug_backtrace();
        if ($function = $trace[1]["function"]) {
            $key = $function . "_" . $key;
            if ($class = $trace[1]["class"]) {
                $key = str_replace("\\", "_", $class) . "_" . $key;
            }
        }

        if (static::check($key)) {
            return static::get($key);
        }

        $return = $func();

        static::set($key, $return);

        return $return;
    }
492980
public function groups($key = NULL, $value = NULL)
	{
		if ($key === NULL)
			return $this->_groups;
	
		if (is_array($key))
		{
			$this->_groups = $key;
		}
		else
		{
			if ($value === NULL)
				return isset($this->_groups[$key]) ? $this->_groups[$key] : NULL;
	
			$this->_groups[$key] = $value;
		}
	
		return $this;
	}
660518
function SetGroupBy ( $attribute, $func, $groupsort="@group desc" )
    {
        assert ( is_string($attribute) );
        assert ( is_string($groupsort) );
        assert ( $func==SPH_GROUPBY_DAY
            || $func==SPH_GROUPBY_WEEK
            || $func==SPH_GROUPBY_MONTH
            || $func==SPH_GROUPBY_YEAR
            || $func==SPH_GROUPBY_ATTR
            || $func==SPH_GROUPBY_ATTRPAIR );

        $this->_groupby = $attribute;
        $this->_groupfunc = $func;
        $this->_groupsort = $groupsort;
    }
57524
public function walk(callable $func, $recursively = false)
    {
        if (true === $recursively) {
            array_walk_recursive($this->elements, $func);
        } else {
            array_walk($this->elements, $func);
        }

        return $this;
    }
511251
private function filter(callable $f, $d = null, $k = null) {return 
		dfc($this, function($f, $d, $k) {return
			call_user_func($f, $this->v($d, $k))
		;}, [$f, $d, $k ?: df_caller_f(1)])
	;}
267058
public function callback($func) {
        if (!$this->_isValid) {
            return $this;
        }
        $this->_isValid = (bool) $func($this->_unsafeVar);
        return $this;
    }
354544
public function copyfrom($var,$func=NULL)
    {
        if (is_string($var)) {
            $var = Base::instance()->get($var);
        }
        if ($func) {
            $var = call_user_func($func, $var);
        }
        foreach ($var as $key=>$val) {
            if (
                array_key_exists($key, $this->fields)
                || array_key_exists($key, $this->extras)
            ) {
                $this->set($key,$val);
            }
        }
    }
429765
public function aggregate($function, $fields=null)
    {
        $query = clone $this->_query;

        return $query->select(sprintf('%s(%s)', $function, $fields))->execute()->scalar();
    }
703609
public function unsetData($key = null)
    {
        if ($key === null) {
            $this->data = [];
        }

        if ($key !== null and isset($this->data[$key])) {
            unset($this->data[$key]);
        }
    }
387917
final public function groupBy($fields) {
      if (func_num_args()>0) {
         if (func_num_args()==1) {
            if (!is_array($fields)) {
               $fields = (array) $fields;
            }
         }else{
            $fields = func_get_args();
         }

         $this->groupBy = " GROUP BY ".implode(',',$fields);

         $this->find_first_data = $this->find_save_data = $this->find_delete_data = FALSE;
         
         $this->get_instance();
         return $this;
      }
      return null;
   }
1321262
public function aggregate($function, $columns = ['*'])
	{
		$results = $this
			->cloneWithout(['columns'])
			->cloneWithoutBindings(['select'])
			->setAggregate($function, $columns)
			->getRaw($columns);

		if(count($results))
		{
			return array_change_key_case((array) $results[0])['aggregate'];
		}
	}
1156270
public function groupBy(callable $func)
    {
        $result = [];
        foreach ($this->each() as $k => $v) {
            $this->_groupBy($result, $k, $v, $func);
        }
        return $result;
    }