Returns a new sorted collection using a user-defined comparison function.

@param Closure $callback The user-defined comparison function.

@return Collection A new collection instance.
337603
public function sort(Closure $callback = null): CollectionInterface
    {
        $array = $this->toArray();

        if (is_null($callback)) {
            sort($array);
        } else {
            usort(
                $array,
                $callback
            );
        }

        return static::make($array);
    }
522886
public function previousAll(callable $callback = NULL) {
    $matches = [];
    foreach ($this->nodes as $node) {
      $matches = array_merge($matches, $node->previousAll($callback)->nodes);
    }
    return new NodeCollection($matches);
  }
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);
    }
890885
public static function object(\Closure $callback) {
		$obj = new Object;
		$callback->__invoke($obj);
		return json_encode($obj);
	}
744976
public function map(\Closure $callback) : Collection
    {
        $keys = array_keys($this->data);
        $values = array_map($callback, $this->data, $keys);

        return static::create(array_combine($keys, $values));
    }
383897
public function filter(Closure $callback)
    {
        $filtered_map = new static;

        foreach ($this->items as $key => $item) {
            if ($callback($item) === true) {
                $filtered_map->setItem($key, $item);
            }
        }

        return $filtered_map;
    }
400456
public function map(\Closure $callback)
    {
        $result = [];
        foreach ($this->value as $entity) {
            $result[] = $callback($entity);
        }

        return $result;
    }
907375
public function make(string $name, ?Closure $callback = null) : Collection {
        return $this->collection($name, $callback);
    }
1253268
public function each(callable $callback): CollectionInterface
    {
        if ($callback instanceof Closure) {
            $callback = $this->bindCallback($callback);
        }

        foreach ($this->generator() as $key => $value) {
            call_user_func($callback, $key, $value);
        }

        return $this;
    }
981898
public function filter(callable $callback): CollectionInterface
    {
        $collection = clone $this;
        $collection->data = \array_merge([], \array_filter($collection->data, $callback));

        return $collection;
    }
1094266
public function map(\Closure $callback)
    {

        $this->_items = array_map($callback, $this->_items);

        return $this;
    }
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);
	}
990842
protected function resolveCriteriaGroupClosure(\Closure $callback): Query
    {
        if ($this->closureResolver === null) {
            return $this->makeCopyForCriteriaGroup()->apply($callback);
        } else {
            return $this->closureResolver->resolveCriteriaGroupClosure($callback);
        }
    }
392921
public static function sort($array, Closure $callback)
    {
        $results = [];

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

        return $results;
    }
215061
public function filter(callable $callback) {
    $matches = [];
    foreach ($this->nodes as $index => $node) {
      if ($callback($node, $index)) {
        $matches[] = $node;
      }
    }
    return new NodeCollection($matches, FALSE);
  }
2580
public function sort(callable $callback = null) : Stack
    {
        $values = $this->_sort($callback);
        $this->setValues($values);
        return $this;
    }
446605
public function first( Closure $callback = NULL, $default = NULL )
    {
        if ( is_null( $callback ) )
        {
            return count( $this->items ) > 0 ? reset( $this->items ) : NULL;
        }

        return array_filter( $this->items, $callback, $default );
    }