Sort the collection of item keys through a user-defined
comparison function.

@param callable|null $callable

@return static
547374
public function sortByKey(callable $callback = null)
    {
        $items = $this->items;

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

        return new static($items);
    }
443175
protected function getCallableParameters(callable $callable)/*# : array */
    {
        // array type
        if (is_array($callable)) {
            $reflector = new \ReflectionClass($callable[0]);
            $method = $reflector->getMethod($callable[1]);

        // object with __invoke() defined
        } elseif ($this->isInvocable($callable)) {
            $reflector = new \ReflectionClass($callable);
            $method = $reflector->getMethod('__invoke');

        // simple function
        } else {
            $method = new \ReflectionFunction($callable);
        }

        return $method->getParameters();
    }
886160
public function sort(callable $closure)
    {
        $entities = $this->_entities;
        usort($entities, $closure);

        $sorted = new Entities();
        foreach ($entities as $entity) {
            $sorted->add($entity);
        }
        return $sorted;
    }
1117271
private function listParameters(callable $callable): array
    {
        $parameters = [];
        foreach ($this->getReflection($callable)->getParameters() as $parameter) {
            $parameters[$parameter->getName()] = $parameter;
        }

        return $parameters;
    }
685889
public function setCallable($callable)
    {
        $matches = array();
        if (is_string($callable) && preg_match('!^([^\:]+)\:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$!', $callable, $matches)) {
            $class = $matches[1];
            $method = $matches[2];
            $callable = function() use ($class, $method) {
                static $obj = null;
                if ($obj === null) {
                    $obj = new $class;
                }
                return call_user_func_array(array($obj, $method), func_get_args());
            };
        }

        if (!is_callable($callable)) {
            throw new \InvalidArgumentException('Route callable must be callable');
        }

        $this->callable = $callable;
    }
1178155
protected function getFirstFromProviders(callable $callable, $default = null)
    {
        $values = array_filter(array_map($callable, $this->providers));

        return empty($values) ? $default : current($values);
    }
683150
public function sort(callable $fn)
    {
        $items = $this->items;
        usort($items, $fn);

        return new self($items);
    }
536592
public function sort(callable $comparator = null) : Collection
    {
        return $this->pipe(
            function (array $value) use ($comparator) : array {
                $comparator !== null
                    ? usort($value, $comparator)
                    : sort($value);

                return $value;
            }
        );
    }
77674
protected function arraySort(callable $cb = null)
    {
        $ar = $this->toArray();
        if ($cb) {
            usort($ar, $cb);
        } else {
            sort($ar);
        }
        return static::fromArray($ar);
    }
517838
public static function getArity($callable)
    {
        if (is_object($callable)) {
            foreach (['__invoke', 'handle'] as $method) {
                if (! method_exists($callable, $method)) {
                    continue;
                }

                $r = new ReflectionMethod($callable, $method);
                return $r->getNumberOfRequiredParameters();
            }
            return 0;
        }

        if (! is_callable($callable)) {
            return 0;
        }

        $r = new ReflectionFunction($callable);
        return $r->getNumberOfRequiredParameters();
    }
979803
public function match($callable)
    {
        ob_start();
        $callable();

        $this->actual = ob_get_contents();
        ob_end_clean();

        return ($this->actual == $this->expected);
    }
747877
public function first($callable = null)
    {
        if ($callable !== null) {
            $result = $this->statement->fetch(PDO::FETCH_ASSOC);
            $this->statement->closeCursor();
            if (is_array($result)) {
                $result = call_user_func_array($callable, $result);
            }
        } else {
            $result = $this->statement->fetch();
            $this->statement->closeCursor();
        }

        return $result;
    }
791326
public function sort(callable $comparator = null): ArrayCollection
    {
        $items = $this->items;

        $comparator ? uasort($items, $comparator) : uasort($items, function ($a, $b) {
            return $a <=> $b;
        });

        return new static($items);
    }
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);
    }
304223
function sortCustomKey(callable $closure) {
        $data = $this->data;
        \uksort($data, $closure);
        
        return (new self($data));
    }
16969
protected function heapSort(callable $cb)
    {
        $h = new CallbackHeap($cb);
        foreach ($this as $el) {
            $h->insert($el);
        }

        return static::fromItems($h);
    }
1358359
public function ordered(callable $comparator = null) : Collection
    {
        return $this->pipe(
            self::predicate(
                function (array $values) use ($comparator) : bool {
                    $sorted = $values;

                    $comparator !== null
                        ? usort($values, $comparator)
                        : sort($values);

                    return $sorted === $values;
                },
                'not ordered'
            )
        );
    }