Force the collection to re-sort itself. You don't need to call this under normal circumstances, as the set will maintain sort order as each item is added.
964086
function(options) {
      options || (options = {});
      if (!this.comparator) throw new Error('Cannot sort a set without a comparator');
      this.models = this.sortBy(this.comparator);
      if (!options.silent) this.trigger('reset', this, options);
      return this;
    }
1242713
def reorder_indices(self, indices_order):
        ''
        # allow mixed index syntax like int
        indices_order, single = convert_index_to_keys(self.indices, indices_order)
        old_indices = force_list(self.indices.keys())

        if indices_order == old_indices: # no changes
            return

        if set(old_indices) != set(indices_order):
            raise KeyError('Keys in the new order do not match existing keys')

#        if len(old_indices) == 0: # already return since indices_order must equal to old_indices
#            return

        # must have more than 1 index to reorder
        new_idx = [old_indices.index(i) for i in indices_order]
        # reorder items
        items = [map(i.__getitem__, new_idx) for i in self.items()]
        self.clear(True)
        _MI_init(self, items, indices_order)
35962
protected function _afterLoadCollection()
    {
        $categories = $this->categoryCollectionFactory->create()
            ->addAttributeToSelect('name')
            ->toOptionArray();

        $collection = clone $this->getCollection();
        $ordered = $this->getCollection()->removeAllItems();
        foreach ($categories as $category) {
            if ($item = $collection->getItemById($category['value'])) {
                $ordered->addItem($item);
            }
        }

        $this->setCollection($ordered);
        return parent::_afterLoadCollection();
    }
1255055
def reorder(things, ids)
      ordered_things = []
      ids.each do |id|
        thing = things.find{ |t| t.id.to_s == id.to_s }
        ordered_things |= [thing] if thing
      end
      ordered_things
    end
823448
protected function sort() {
    if( !empty( $this->_callback_list ) ) {

      // sort by the priorities, but keep the original indexes (we need it for the repopulation)
      $priority_list = $this->_priority_list;
      asort( $priority_list );

      // repopulate the callbacks based on the new priority "map"
      $tmp                  = $this->_callback_list;
      $this->_callback_list = [];
      foreach( $priority_list as $index => $_ ) {
        $this->_callback_list[] = $tmp[ $index ];
      }

      // reset priority indexes (to match the repopulated array)
      $this->_priority_list = array_values( $priority_list );
    }
  }
287025
def reshuffle(expr, by=None, sort=None, ascending=True):
    

    by = by or RandomScalar()

    grouped = expr.groupby(by)
    if sort:
        grouped = grouped.sort_values(sort, ascending=ascending)

    return ReshuffledCollectionExpr(_input=grouped, _schema=expr._schema)
631674
def apply(self, collection, data):
        """"""
        value = self.value(data)
        if value is self.default:
            return collection
        return [o for o in collection if getattr(o, self.name, None) == value]
995723
def reload(self):
        
        enum = self._enum
        if not enum:
            return
        
        self.clear()
        
        if not self.isRequired():
            self.addItem('')
        
        if self.sortByKey():
            self.addItems(sorted(enum.keys()))
        else:
            items = enum.items()
            items.sort(key = lambda x: x[1])
            
            self.addItems(map(lambda x: x[0], items))
1236881
def _on_items_changed(self, change):
        
        if change['type'] != 'container':
            return
        op = change['operation']
        if op == 'append':
            i = len(change['value'])-1
            self.adapter.notifyItemInserted(i)
        elif op == 'insert':
            self.adapter.notifyItemInserted(change['index'])
        elif op in ('pop', '__delitem__'):
            self.adapter.notifyItemRemoved(change['index'])
        elif op == '__setitem__':
            self.adapter.notifyItemChanged(change['index'])
        elif op == 'extend':
            n = len(change['items'])
            i = len(change['value'])-n
            self.adapter.notifyItemRangeInserted(i, n)
        elif op in ('remove', 'reverse', 'sort'):
            # Reset everything for these
            self.adapter.notifyDataSetChanged()
743999
protected function can_be_reset() {

        // Loop through preferences and make sure they are empty or set to the default value.
        foreach ($this->prefs as $prefname => $prefval) {

            if ($prefname === 'sortby' and !empty($this->sort_default_column)) {
                // Check if the actual sorting differs from the default one.
                if (empty($prefval) or $prefval !== array($this->sort_default_column => $this->sort_default_order)) {
                    return true;
                }

            } else if ($prefname === 'collapse' and !empty($prefval)) {
                // Check if there are some collapsed columns (all are expanded by default).
                foreach ($prefval as $columnname => $iscollapsed) {
                    if ($iscollapsed) {
                        return true;
                    }
                }

            } else if (!empty($prefval)) {
                // For all other cases, we just check if some preference is set.
                return true;
            }
        }

        return false;
    }
655167
function(originalIndex, newIndex) {
      if(originalIndex < newIndex) {
         this.items.splice(newIndex+1,0, this.items[originalIndex]);
         this.items[originalIndex] = null;
      }
      else {
         this.items.splice(newIndex,0, this.items[originalIndex]);
         this.items[originalIndex+1] = null;
      }      
      this.items = inputEx.compactArray(this.items);
      
      this.listReorderedEvt.fire();
   }
186293
public boolean isOrderSet() {
        boolean result = true;

        if (this.values.size() != this.order.size()) {
            result = false;
        }

        return result;
    }
1043938
function(new_indices) {

		var i = 0,
			result = this._createHelperStorage(),
			index,
			verification = {};

		if (Lava.schema.DEBUG && new_indices.length != this._count) throw "reorder: new item count is less than current";

		for (; i < this._count; i++) {

			index = new_indices[i];
			result.push(this._data_uids[index], this._data_values[index], this._data_names[index]);

			if (Lava.schema.DEBUG) {
				// duplicate UIDs may break a lot of functionality, in this class and outside
				if (index in verification) Lava.t("Malformed index array");
				verification[index] = null;
			}

		}

		this._assignStorage(result);
		this._fire('collection_changed');

	}
1011593
public function rewind()
    {
        $this->getIteratorObject()->last();

        if ($this->getIteratorObject()->valid()) {
            if (($countItems = $this->countItems()) > 0) {
                $this->_itemPosition = $countItems - 1;
            } else {
                $this->_itemPosition = 0;
            }
        }
    }
74211
public void reindexItems() {
    if (numUnsortedItems > 0) {
      int[] newSortedKeys = Arrays.copyOf(sortedKeys, sortedKeys.length + numUnsortedItems);
      int[] newSortedValues = Arrays.copyOf(sortedValues, sortedValues.length + numUnsortedItems);

      int oldLength = sortedKeys.length;
      for (int i = 0; i < numUnsortedItems; i++) {
        newSortedKeys[i + oldLength] = unsortedKeys[i];
        newSortedValues[i + oldLength] = unsortedValues[i];
      }

      ArrayUtils.sortKeyValuePairs(newSortedKeys, newSortedValues, 0, newSortedKeys.length);

      sortedKeys = newSortedKeys;
      sortedValues = newSortedValues;
      numUnsortedItems = 0;
      
      rebuildKeySet();
    }
  }
168128
def sort(self, callback=None):
        
        items = self.items

        if callback:
            return self.__class__(sorted(items, key=callback))
        else:
            return self.__class__(sorted(items))
256986
function (collection) {
    if (!collection || !_.isObject(collection)) {
      var err = new Error('Please pass a valid collection!');
      debug(err);
      throw err;
    }

    this.collection = collection;
  }