Function in collections coil-stdlib

sort

fn sort<T: Ord>(Vec<T> arr) -> Vec<T>
Import
use collections::{sort};
Source: src/collections.hy

Returns a sorted copy of arr, in ascending order.

The sort is stable (equal elements keep their order) and takes O(n log n) time. arr itself is not changed. Elements need Ord; strings compare by their UTF-8 bytes, so "B" sorts before "a".

Parameters#

NameType
arrVec<T>

Returns#

Vec<T>

Contracts#

Checked according to --contracts (see Contracts).

ensures result.len() == arr.len()

Examples#

use collections::{sort};
use tests::assert;
let xs: Vec<int> = [3, 1, 2];
let s = sort(xs);
assert!(s[0] == 1 && s[2] == 3);
assert!(xs[0] == 3);
let words: Vec<string> = ["pear", "Apple", "fig"];
assert!(sort(words)[0] == "Apple");

See also#

  • Ord
  • sort_by: Returns a copy of arr sorted by the value key gives each element, in ascending order.
  • reverse: Returns a copy of arr in reverse order.
  • collect_ints: Returns the values of the range a..b as a Vec<int>.
  • collect_ints_inclusive: Returns the values of the inclusive range a..=b as a Vec<int>.
↑ ↓ navigate ↵ open