Sort an collection by values using a user-defined comparison function

@param \Closure $callback
@param bool $save_keys maintain index association
@return static
43
public function sortBy( \Closure $callback, bool $save_keys = true )
	{
		$items = $this->items;
		$save_keys ? uasort($items, $callback) : usort($items, $callback);
		return new static($items);
	}
1152872
public function sort($key = null, $rule = "", $save_key = true)
    {
        $this->sortArray($key, $rule, 'asc', $save_key);
        return $this;
    }
1068541
public static function cache($key, Closure $callback) {
        if (is_array($key)) {
            $key = implode('-', $key);
        }

        if (isset(self::$_cache[$key])) {
            return self::$_cache[$key];
        }

        self::$_cache[$key] = $callback();

        return self::$_cache[$key];
    }
194676
public function sort(\Closure $compare = null){
		
		if($this->_ReadOnly){
			throw new ReadOnlyException(\get_called_class() . ' is read only');
		}
		
		if(\is_callable($compare)){
			\usort($this->_Arr, $compare);
		}
		else{
			\sort($this->_Arr);
		}
		
		return $this;
		
	}
1321626
public static function where($array, \Closure $callback)
        {
            $filtered = array();

            foreach ($array as $key => $value) {
                if (call_user_func($callback, $key, $value)) {
                    $filtered[$key] = $value;
                }
            }

            return $filtered;
        }
235021
protected function incrementOrDecrement($key, $value, Closure $callback)
    {
        return $this->connection->transaction(function () use ($key, $value, $callback) {
            $prefixed = $this->prefix.$key;

            $cache = $this->table()->where('key', $prefixed)
                        ->lockForUpdate()->first();

            // If there is no value in the cache, we will return false here. Otherwise the
            // value will be decrypted and we will proceed with this function to either
            // increment or decrement this value based on the given action callbacks.
            if (is_null($cache)) {
                return false;
            }

            $cache = is_array($cache) ? (object) $cache : $cache;

            $current = $this->unserialize($cache->value);

            // Here we'll call this callback function that was given to the function which
            // is used to either increment or decrement the function. We use a callback
            // so we do not have to recreate all this logic in each of the functions.
            $new = $callback((int) $current, $value);

            if (! is_numeric($current)) {
                return false;
            }

            // Here we will update the values in the table. We will also encrypt the value
            // since database cache values are encrypted by default with secure storage
            // that can't be easily read. We will return the new value after storing.
            $this->table()->where('key', $prefixed)->update([
                'value' => $this->serialize($new),
            ]);

            return $new;
        });
    }
1100071
public function sortMultiDimension(Closure $callback)
    {
        foreach ($this->items as &$sortable) {
            uasort($sortable, $callback);
        }
        unset($sortable);

        return $this;
    }
132087
public function mapWithKeys(callable $callback): CollectionInterface
    {
        return $this->wrap(function (Iterator $data) use ($callback) {
            foreach ($data as $key => $value) {
                /** @var iterable $result */
                $result = $callback($value, $key);

                foreach ($result as $resultKey => $resultValue) {
                    yield $resultKey => $resultValue;
                }
            }
        });
    }
1130100
public function filter(\Closure $callback = null) : Collection
    {
        if ($callback) {
            return static::create(array_filter($this->data, $callback));
        }

        return static::create(array_filter($this->data));
    }
98525
public function sort(callable $callback = null)
    {
        $items = $this->items;

        $callback = $callback ?: function ($a, $b) {
            return $a == $b ? 0 : (($a < $b) ? -1 : 1);

        };

        uasort($items, $callback);

        return new static($items);
    }
215649
protected function bindOriginalRow(Closure $callback, $key)
    {
        $originalRow = static::$originalGridData[$key];

        return $callback->bindTo(static::$model->newFromBuilder($originalRow));
    }
512458
function sortCustom(callable $closure) {
        $args = $this->baseStorageArgs;
        $args[] = parent::sortCustom($closure)->all();
        
        return (new static(...$args));
    }
1239031
function sortCustomKey(callable $closure) {
        $args = $this->baseStorageArgs;
        $args[] = parent::sortCustomKey($closure)->all();
        
        return (new static(...$args));
    }
847026
public function sort(callable $callback = null, $desc = false)
    {
        if (!$callback || !\is_callable($callback)) {
            return $this;
        }

        $items = $this->items;
        uasort($items, $callback);

        return !$desc ? $items : array_reverse($items, true);
    }
119265
public function indexBy($callback)
    {
        $keys = array_map($callback, $this->value);
        $value = array_combine($keys, $this->value);
        return $this->setValue($value);
    }
1144358
public function mapKeys(callable $callback, callable $callbackValue = null): self
    {
        $collection = Factory::create();
        $index      = 0;
        foreach ($this->items as $key => $value) {
            $collection->set(
                $callback($value, $key, $index),
                null === $callbackValue ? $value : $callbackValue($value, $key, $index)
            );
            ++$index;
        }

        return $collection;
    }
595489
public function partition(callable $callback, $keepKey = false)
    {
        $true = [];
        $false = [];

        if (is_string($callback)) {
            $callback = function ($value) use ($callback) {
                return $callback($value);
            };
        }

        foreach ($this->convertArray($this) as $key => $value) {
            if ($callback($value, $key)) {
                $true[$key] = $value;
            } else {
                $false[$key] = $value;
            }
        }

        if (!$keepKey) {
            $true = array_values($true);
            $false = array_values($false);
        }

        return [
            $this->bindNewInstance($true),
            $this->bindNewInstance($false),
        ];
    }