Sort array data

@param callable $callback

@return Stack
2580
public function sort(callable $callback = null) : Stack
    {
        $values = $this->_sort($callback);
        $this->setValues($values);
        return $this;
    }
1239310
private function getCallback($callback)
    {
        if (is_callable($callback)) {
            if (is_array($callback)) {
                $callback = function (Vertex $vertex) use ($callback) {
                    return call_user_func($callback, $vertex);
                };
            }
            return $callback;
        }

        static $methods = array(
            self::ORDER_ID => 'getId',
            self::ORDER_GROUP => 'getGroup'
        );

        if (!is_int($callback) || !isset($methods[$callback])) {
            throw new InvalidArgumentException('Invalid callback given');
        }

        $method = $methods[$callback];

        return function (Vertex $vertex) use ($method) {
            return $vertex->$method();
        };
    }
547374
public function sortByKey(callable $callback = null)
    {
        $items = $this->items;

        $callback
            ? uksort($items, $callback)
            : ksort($items);

        return new static($items);
    }
1336106
protected function buildQueueCallable($callback)
	{
		if ( !$callback instanceof Closure )
		{
			return $callback;
		}

		if ( class_exists('\SuperClosure\Serializer') )
		{
			return (new \SuperClosure\Serializer)->serialize($callback);
		}
		else
		{
			return serialize(new \Illuminate\Support\SerializableClosure($callback));
		}
	}
1034582
public function sortBy(Closure $callback, $args = array(), $asc = false)
        {
            $results = array();

            foreach ($this->_items as $key => $value) {
                array_push($args, $value);
                $results[$key] = call_user_func_array($callback, $args);
            }

            if (true === $asc) {
                asort($results);
            } else {
                arsort($results);
            }

            foreach (array_keys($results) as $key) {
                $results[$key] = $this->_items[$key];
            }

            $this->_items = $results;

            return $this;
        }
1311185
private function _last(callable $callback = null)
    {
        $values = $this->getValues();
        if ($callback){
            foreach(array_reverse($values) as $key => $value){
                if ($callback($value, $key)){
                    return $value;
                }
            }
        }
        else{
            return empty($values) ? null : $values[count($values)-1];
        }
        return null;
    }
339498
public function sortBy(\Closure $callback , $asc = false)
    {
        $results = array();

        foreach ($this->_items as $key => $value) {
            $results[$key] = $callback($value);
        }

        if ($asc) {
            asort($results);
        } else {
            arsort($results);
        }

        foreach (array_keys($results) as $key) {
            $results[$key] = $this->_items[$key];
        }

        $this->_items = $results;

        return $this;
    }
1066566
public function map($callback) : ArrayList
    {
        $values = $this->_map($callback);
        $this->setValues($values);
        return $this;
    }
512458
function sortCustom(callable $closure) {
        $args = $this->baseStorageArgs;
        $args[] = parent::sortCustom($closure)->all();
        
        return (new static(...$args));
    }
671832
public function find(callable $callback)
    {
        $array = $this->getArrayCopy();
        foreach ($array as $key => $value) {
            if ($callback($value, $key, $array) === true) {
                return $value;
            }
        }
    }
54120
public function map(callable $callback): Sequence
    {
        $items = $this->items->map($callback);

        return $this->duplicate($items);
    }
948867
public function sort( $callback ) {
		$elements = $this->elements;
		usort( $elements, $callback );
		return $this->new_from_trusted( $elements );
	}
1110130
public function map(callable $callback = null)
	{
		return $callback ? array_map($callback, $this->list) : $this->list;
	}
660278
public function each($callback)
    {
        array_walk($this->array, function($value, $key) use ($callback) {
            $callback($key, $value);
        });

        return $this;
    }
416927
public function filter(callable $callback = null)
    {
        if ($callback === null) {
            return new static(\array_filter($this->all()));
        }

        return new static(\array_filter($this->all(), $callback));
    }
1112824
public static function mergeSort(&$array, \Closure $callback)
    {
        // Arrays of size < 2 require no action.
        if (count($array) < 2) {
            return;
        }

        // Split the array in half
        $halfway = count($array) / 2;
        $array1 = array_slice($array, 0, $halfway);
        $array2 = array_slice($array, $halfway);

        // Recurse to sort the two halves
        self::mergeSort($array1, $callback);
        self::mergeSort($array2, $callback);

        // If all of $array1 is <= all of $array2, just append them.
        if (call_user_func($callback, end($array1), $array2[0]) < 1) {
            $array = array_merge($array1, $array2);

            return;
        }

        // Merge the two sorted arrays into a single sorted array
        $array = [];
        $ptr1 = $ptr2 = 0;

        while ($ptr1 < count($array1) && $ptr2 < count($array2)) {
            if ($callback($array1[$ptr1], $array2[$ptr2]) < 1) {
                $array[] = $array1[$ptr1++];
            } else {
                $array[] = $array2[$ptr2++];
            }
        }
        // Merge the remainder
        while ($ptr1 < count($array1)) {
            $array[] = $array1[$ptr1++];
        }

        while ($ptr2 < count($array2)) {
            $array[] = $array2[$ptr2++];
        }
    }
1046896
public function sort(callable $callback = null) : ArrayList
    {
        $values = $this->_sort($callback);
        $this->setValues($values);
        return $this;
    }