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

@param \Closure $callback
@return static
778677
public function sortByKeys( \Closure $callback )
	{
		$items = $this->items;
		uksort($items, $callback);
		return new static($items);
	}
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;
        }
215061
public function filter(callable $callback) {
    $matches = [];
    foreach ($this->nodes as $index => $node) {
      if ($callback($node, $index)) {
        $matches[] = $node;
      }
    }
    return new NodeCollection($matches, FALSE);
  }
890885
public static function object(\Closure $callback) {
		$obj = new Object;
		$callback->__invoke($obj);
		return json_encode($obj);
	}
512458
function sortCustom(callable $closure) {
        $args = $this->baseStorageArgs;
        $args[] = parent::sortCustom($closure)->all();
        
        return (new static(...$args));
    }
1104347
public function uksort(callable $callback): Collection
    {
        $items = $this->items;
        $keys = array_combine(array_keys($items), range(1, count($items)));

        uksort($items, function ($a, $b) use ($callback, $keys) {
            $result = call_user_func($callback, $a, $b);

            return $result === 0 ? $keys[$a] - $keys[$b] : $result;
        });

        return new static($items);
    }
660278
public function each($callback)
    {
        array_walk($this->array, function($value, $key) use ($callback) {
            $callback($key, $value);
        });

        return $this;
    }
178117
public function filter(callable $callback = null): CollectionInterface
    {
        if (!$callback) {
            $callback = function ($item) {
                return (bool)$item;
            };
        }

        return $this->wrap(function (Iterator $data) use ($callback) {
            foreach ($data as $key => $item) {
                if ($callback($item, $key)) {
                    yield $key => $item;
                }
            }
        });
    }
808260
public function sortBy($callback, $options = SORT_REGULAR, $descending = false)
    {
        $results = array();

        if (is_string($callback)) {
            $callback = $this->valueRetriever($callback);
        }

        // First we will loop through the items and get the comparator from a callback
        // function which we were given. Then, we will sort the returned values and
        // and grab the corresponding values for the sorted keys from this array.
        foreach ($this->items as $key => $value) {
            $results[$key] = $callback($value);
        }

        $descending ? arsort($results, $options) : asort($results, $options);

        // Once we have sorted all of the keys in the array, we will loop through them
        // and grab the corresponding model so we can set the underlying items list
        // to the sorted version. Then we'll just return the collection instance.
        foreach (array_keys($results) as $key) {
            $results[$key] = $this->items[$key];
        }

        $this->items = $results;

        return $this;
    }
712786
public function each($callback)
    {
        Argument::i()->test(1, 'callable');

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

        return $this;
    }
1025082
public function map(callable $callback): CollectionInterface
    {
        return $this->wrap(function (Iterator $data) use ($callback) {
            foreach ($data as $key => $value) {
                yield $key => $callback($value, $key);
            }
        });
    }
2580
public function sort(callable $callback = null) : Stack
    {
        $values = $this->_sort($callback);
        $this->setValues($values);
        return $this;
    }
948867
public function sort( $callback ) {
		$elements = $this->elements;
		usort( $elements, $callback );
		return $this->new_from_trusted( $elements );
	}
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];
    }
25630
public function group(callable $callback) {
		$array = array();
		foreach ($this->getIterator() as $index => $item) {
			$group = $callback($item);
			$array[$group][] = $item;
		}
		return new static($array);
	}
1318825
public function filter(\Closure $callback)
    {
        $collection = new static();

        foreach ($this as $element) {
            if ($callback($element)) {
                $collection->attach($element);
            }
        }

        return $collection;
    }
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;
    }