Home / Docs / Standard library / Prelude
sort
Release v0.4.0Edition 0.2 and later
A function of the prelude, in scope in every module. Edition 0.2 and later.
una
pub sort[T: Ord](xs: List[T]) -> List[T]
ensures result.len == xs.lenThe elements of xs in ascending order, equal ones in their order in xs (spec/20 §6).
Parameters
xs: the list
Returns
List[T]: the elements of xs in ascending order, equal ones in their order in xs; as many as xs.
Example
src/shop.una
module shop
--- A cart's prices, lowest first.
pub main() -> Unit
uses @console: Console[print]
=
let sorted = [1999, 499, 2499].sort()
let shown = sorted.map(each: fn(p) -> "{p}")
@console.print(join(shown, separator: ", "))una run . prints:
Output
499, 1999, 2499Specification
Generated from the standard modules of una v0.4.0 (docs/std/listing.json, which is not part of the specification). The specification governs: spec/14 §1.