Sort triggers based on type and word count from
largest to smallest.

@param Collection $triggers

@return Collection
4790
protected function sortTriggers($triggers)
    {
        $triggers = $this->determineWordCount($triggers);
        $triggers = $this->determineTypeCount($triggers);

        $triggers = $triggers->sort(function ($current, $previous) {
            return ($current['order'] < $previous['order']) ? -1 : 1;
        })->reverse();

        return $triggers;
    }
104107
public function sortByField($field, $collection)
    {
        if ($collection->isEmpty()) {
            return 'N/A';
        }

        return $collection->groupBy($field)->sortByDesc(function ($logs) {
            return count($logs);
        })->first()->pluck($field)->first();
    }
479577
private function validateCollection($collection)
    {
        if ($collection === false)
            return $collection;
        $resolver = new OptionsResolver();
        $resolver->setRequired([
            'form',
            'rows',
        ]);
        $resolver->setDefaults([
            'buttons' => [],
            'sortBy' => false,
            'headerRow' => false,
        ]);
        $resolver->setAllowedTypes('form', ['string']);
        $resolver->setAllowedTypes('rows', ['array']);
        $resolver->setAllowedTypes('buttons', ['array']);
        $resolver->setAllowedTypes('sortBy', ['array', 'boolean']);
        $resolver->setAllowedTypes('headerRow', ['array', 'boolean']);
        $collection = $resolver->resolve($collection);
        $this->addFormTabMap($collection['form']);
        $collection['rows'] = $this->validateRows($collection['rows']);
        $collection['headerRow'] = $this->validateRow($collection['headerRow']);
        $collection['buttons'] = $this->validateButtons($collection['buttons']);
        if (is_array($collection['sortBy']) && count($collection['sortBy']) > 3)
            trigger_error(sprintf('The depth of sort for a collection is limited to 3 levels. %d > 3', count($collection['sortBy'])), E_USER_ERROR);
        
        return $collection;
    }
474163
protected function sortListeners(string $event) : interfaces\Emitter
    {
        if (!isset($this->listeners[$event])) {
            return $this;
        }

        // Sort the listeners by priority in a descending order.
        krsort($this->listeners[$event]);

        $this->chain[$event] = array_merge(...$this->listeners[$event]);

        return $this;
    }
1050908
protected function mapRules($rules) : Collection
	{
		return Collection::make($rules)
			->only($this->allowed)
			->flatMap(function ($item, $key) {
				if ($key == 'required') {
					$rule[] = $item ? 'required' : '';
				} else {
					$rule[] = $key . ':' . $item;
				}
				return $rule;
			});
	}
442032
public function orderBy(array $orderings) : self
    {
        $this->orderings = array_map(
            static function (string $ordering) : string {
                return strtoupper($ordering) === Criteria::ASC ? Criteria::ASC : Criteria::DESC;
            },
            $orderings
        );

        return $this;
    }
411668
private function sort(array $databases, $sort, $reverseSort)
    {
        switch ($sort) {
            case 'name':
                ksort($databases);
                break;

            case 'size':
                uasort(
                    $databases,
                    function ($a, $b) {
                        return $a['size'] > $b['size'];
                    }
                );
                break;

            default:
                throw new Exception\DomainException("Invalid sort option \"$sort\".");
        }

        if ($reverseSort) {
            $databases = array_reverse($databases, true);
        }

        return $databases;
    }
96311
protected function sortHandlers(string $eventType): void
    {
        $this->sorted[$eventType] = [];
        if (isset($this->handlers[$eventType])) {
            krsort($this->handlers[$eventType]);
            $this->sorted[$eventType] = call_user_func_array(
                'array_merge',
                $this->handlers[$eventType]
            );
        }
    }
427345
private function sort(array $tables, $sort, $reverseSort)
    {
        switch ($sort) {
            case 'name':
                ksort($tables);
                break;

            case 'size':
                uasort(
                    $tables,
                    function ($a, $b) {
                        return $a['size'] > $b['size'];
                    }
                );
                break;

            default:
                throw new Exception\DomainException("Invalid sort option \"$sort\".");
        }

        if ($reverseSort) {
            $tables = array_reverse($tables, true);
        }

        return $tables;
    }
394348
public static function sort(array $versions) : array
    {
        usort(
            $versions,
            function (Version $a, Version $b) {
                return VersionComparator::compare($a, $b);
            }
        );

        return $versions;
    }
996769
protected function sort(\Iterator $files)
    {
        $sorted = new \SplPriorityQueue();
        foreach ($files as $file) {
            preg_match(
                '/\d+/',
                $files->current(),
                $priority
            );
            if (empty($priority))
                continue;

            $sorted->insert($files->current(), $priority[0]);
        }
        return $sorted;
    }
841032
public function renumberCollection(Collection $collection)
    {
        $i = 0;

        foreach ( $collection as $item ) {
            if ( $item instanceof NumericallySortableContract ) {
                $item->updateSortingOrder(++$i);
            }
        }

        return $this;
    }
55921
protected function searchTriggers($trigger)
    {
        synapse()->triggers->each(function ($class) use ($trigger) {
            $triggerClass = "\\Axiom\\Rivescript\\Cortex\\Triggers\\$class";
            $triggerClass = new $triggerClass();

            $found = $triggerClass->parse($trigger, $this->input);

            if ($found === true) {
                $this->getResponse($trigger);

                return false;
            }
        });
    }
925318
private function _sortIndex()
    {
        $collection = ResourceTable::collection();
        $sort = $collection->getSort();

        return $sort['index'] ? $sort['index'] : null;
    }
1167432
public function sort($fields)
    {
        foreach ($fields as $fieldName => $order) {
            if (is_string($order)) {
                $order = strtolower($order) === 'asc' ? 1 : -1;
            }

            if (is_scalar($order)) {
                $fields[$fieldName] = (integer) $order;
            }
        }
        $this->sort = $fields;
        $this->riakCursor->sort($fields);
        return $this;
    }
498270
public function max($collection=null, $iterator=null) {
    list($collection, $iterator) = self::_wrapArgs(func_get_args(), 2);
    
    if(is_null($iterator)) return self::_wrap(max($collection));
    
    $results = array();
    foreach($collection as $k=>$item) {
      $results[$k] = $iterator($item);
    }
    arsort($results);
    $__ = new self;
    $first_key = $__->first(array_keys($results));
    return $collection[$first_key];
  }
155064
public function sort($callback)
    {
        $newCollection = clone $this;
        \uasort($newCollection->arrCollection, $callback);

        $newCollection->arrCollection = \array_values($newCollection->arrCollection);

        return $newCollection;
    }