@param callable $orderByFunction
@param boolean  $isAscending

@return IOrderedIterator
325901
final public function thenOrderBy(callable $orderByFunction, $isAscending)
    {
        $newOrderedIterator = new self($this->getSourceIterator(), function () {
        }, true);

        $newOrderedIterator->orderByFunctions   = $this->orderByFunctions;
        $newOrderedIterator->isAscendingArray   = $this->isAscendingArray;
        $newOrderedIterator->orderByFunctions[] = Functions::allowExcessiveArguments($orderByFunction);
        $newOrderedIterator->isAscendingArray[] = $isAscending;

        return $newOrderedIterator;
    }
174710
public static function sortBy($xs, $f)
    {
        foreach (ArrayImpl::sortBy($xs, $f) as $k => $x) {
            yield $k => $x;
        }
    }
130918
public function sortBy($callback, $options = SORT_REGULAR, $descending = false)
    {
        $results = [];

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

                foreach (explode('.', $callback) as $segment) {
                    if (is_array($item)) {
                        if ( ! array_key_exists($segment, $item)) {
                            return null;
                        }

                        $item = $item[$segment];
                    }
                }

                return $item;
            };
        }

        // 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;
    }
465922
@WithBridgeMethods(value = OracleQuery.class, castRequired = true)
    public C orderSiblingsBy(Expression<?> path) {
        return addFlag(Position.BEFORE_ORDER, ORDER_SIBLINGS_BY, path);
    }
1259389
public static <T> Function<Iterable<T>, T> minFunction(final Ordering<T> ordering) {
    return new Function<Iterable<T>, T>() {
      @Override
      public T apply(Iterable<T> input) {
        return ordering.min(input);
      }
    };
  }
871674
private function _prepareOrderBy()
	{
		$sQuery = '';

		if (is_array($this->_aOrderBy) && count($this->_aOrderBy) > 0) {

			$sQuery .= ' ORDER BY '.implode(',', $this->_aOrderBy).' ';
		}

		return $sQuery;
	}
926970
public function orderBy($columns, $order = 'ASC', $nulls = null)
    {
        return $this->buildSelect()->orderBy($columns, $order, $nulls);
    }
347681
protected function getOrderByExpressionAsString(InternalOrderByInfo $orderBy)
    {
        $result = '';
        foreach ($orderBy->getOrderByInfo()->getOrderByPathSegments() as $order) {
            foreach ($order->getSubPathSegments() as $subOrder) {
                $result .= $result ? ', ' : '';
                $result .= $subOrder->getName();
                $result .= $order->isAscending() ? ' ASC' : ' DESC';
            }
        }
        return $result;
    }
383028
public function orderBy(string $sort, string $order = 'ASC'): self
    {
        $order = 'ASC' === strtoupper($order) ? 'ASC' : 'DESC';
        $this->orderBy = [$sort => $order];
        return $this;
    }
960439
public function orderBy($type = null)
    {
        if ($type === null) {
            $target = null;

        } elseif ($type instanceof RawSqlFragmentInterface) {
            $target = $type->getFragment();

        } elseif (is_array($type)) {
            // Special case for non-associative array
            if (!ArrayUtils::isAssoc($type)) {
                // Check if at least one value represents a raw fragment
                foreach ($type as &$option) {
                    // If raw, then do nothing but get it
                    if ($option instanceof RawSqlFragmentInterface) {
                        $option = $option->getFragment();
                    } else {
                        // Not raw - OK, then just quote it
                        $option = $this->quote($option);
                    }
                }
            } else {
                // If associative array supplied then assume that values represent sort orders
                $result = array();

                foreach ($type as $column => $sortOrder) {
                    // Force sorting method to be in upper case
                    $sortOrder = strtoupper($sortOrder);

                    // Ensure that only valid sorting methods provided
                    if (!in_array($sortOrder, array('ASC', 'DESC'))) {
                        throw new LogicException(sprintf(
                            'Only ASC and DESC methods are supported. You provided "%s"', $sortOrder
                        ));
                    }

                    // Only column names should be wrapped around backticks
                    array_push($result, sprintf('%s %s', $this->quote($column), $sortOrder));
                }

                $type = $result;
            }

            $target = implode(', ', $type);

        } else {
            $target = $this->quote($type);
        }

        $this->append(' ORDER BY '.$target);
        return $this;
    }
754601
public static Boolean isAscendingOrder(String sorting) {
        return "desc".equalsIgnoreCase(sorting) ? Boolean.FALSE : Boolean.TRUE;
    }
1220238
protected function buildOrder($query, $filter, $order, $direction)
    {
        if (!empty($order)) {
            $direction = empty($direction) ? 'asc' : $direction;
            $query     = $query->orderBy($order, $direction);
        }

        return $query;
    }
466783
public function listOrders($baseIds, $offsetStart = 0, $perPage = 20, $sort = "created_on", $filters = [])
    {
        $qb = $this
            ->createQueryBuilder('o');

        $this->performQuery($qb, $baseIds, $filters);
        $qb->groupBy('o.id');

        if ($sort === 'user') {
            $qb->orderBy('o.user', 'ASC');
        }
        elseif ($sort === 'usage') {
            $qb->orderBy('o.orderUsage', 'ASC');
        }
        else {
            $qb->orderBy('o.createdOn', 'DESC');
        }

        $qb
            ->setFirstResult((int)$offsetStart)
            ->setMaxResults(max(10, (int)$perPage));

        return $qb->getQuery()->getResult();
    }
75059
public <R> AnimaQuery<T> order(TypeFunction<T, R> function, OrderBy orderBy) {
        String columnName = AnimaUtils.getLambdaColumnName(function);
        return order(columnName, orderBy);
    }
1271919
private function sortableCall($function, $arguments)
    {
        $function = strtolower(trim($function));
        if ($this->sortableIsByReferenceMethod($function)) {
            return $this->sortableCallByReference($function, $arguments);
        }

        if ($this->sortableIsByValueMethod($function)) {
            return $this->sortableCallByValue($function, $arguments);
        }

        if ($this->sortableIsSpecialMethod($function)) {
            return $this->sortableCallSpecial($function, $arguments);
        }

        throw new \BadMethodCallException(__CLASS__ . '->' . $function);
    }
393065
public function sortable(
        array $orderColumns = [],
        string $orderByKey = 'order_by',
        string $directionKey = 'direction'
    ): void {
        $model = $this->resolveQueryBuilderFromModel($this->model);
        $request = $this->app->make('request');

        $orderByValue = $request->input($orderByKey);
        $directionValue = $request->input($directionKey);

        $this->set('filter.order_by', ['key' => $orderByKey, 'value' => $orderByValue]);
        $this->set('filter.direction', ['key' => $directionKey, 'value' => $directionValue]);
        $this->set('filter.columns', $orderColumns);

        $this->model = $this->setupBasicQueryFilter($model, [
            'order_by' => $orderByValue,
            'direction' => $directionValue,
            'columns' => $orderColumns,
        ]);
    }
316689
static function active( $asObject = true, $offset, $limit, $sortField = "created", $sortOrder = "asc", $show = eZOrder::SHOW_NORMAL )
    {
        if ( $sortField == "user_name" )
        {
            $db = eZDB::instance();

            $db_params = array();
            $db_params["offset"] =(int) $offset;
            $db_params["limit"] =(int) $limit;
            $sortOrder = $db->escapeString( $sortOrder );

            $query = "SELECT ezorder.*
                      FROM
                            ezorder,
                            ezcontentobject
                      WHERE
                            ".eZOrder::getShowOrdersQuery( $show, "ezorder" )." AND
                            ezorder.is_temporary = '0' AND
                            ezcontentobject.id = ezorder.user_id
                      ORDER BY ezcontentobject.name $sortOrder";
            $orderArray = $db->arrayQuery( $query, $db_params );
            if ( $asObject )
            {
                $retOrders = array();
                foreach ( $orderArray as $order )
                {
                    $order = new eZOrder( $order );
                    $retOrders[] = $order;
                }
                return $retOrders;
            }
            else
            {
                return $orderArray;
            }
        }
        else
        {
            $where['is_temporary'] = 0;
            if ( $show != eZOrder::SHOW_ALL )
            {
                $where['is_archived'] = $show;
            }

            return eZPersistentObject::fetchObjectList( eZOrder::definition(),
                                                        null,
                                                        $where ,
                                                        array( $sortField => $sortOrder ),
                                                        array( 'offset' => $offset,
                                                               'length' => $limit ), $asObject );
        }
    }