---
title: "sort"
url: https://una-lang.org/en/docs/std/prelude/sort/
release: v0.4.0
edition: "0.2 and later"
source: https://github.com/una-lang/una/blob/v0.4.0/docs/std/listing.json
---

# sort

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.len
```

The 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`

```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:

```text
499, 1999, 2499
```

## Specification

- [`spec/20 §6`](https://una-lang.org/en/docs/spec/20-constraints-on-generics/#s6)

Generated from the standard modules of una v0.4.0 ([`docs/std/listing.json`](https://github.com/una-lang/una/blob/5fec93d88932b333feec25e589355a2cb34c37b5/docs/std/listing.json), which is not part of the specification). The specification governs: [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1).
