# std/order

Orders, the comparison under one, and the functions that sort by one. `Asc`, `Desc`, `Then`, `Elem`, `Order` and `before` are compiler-known: an order is a type, never a value, and only these three make one. The ascending order of `T`: by each named field in turn, or by `T`'s own value with no field. `Asc<Person, age>` orders people by age. A key is an integer, a `Bool` or a `String`; `String`s compare bytewise.

## Asc

`type`, at line 8.

```vyrn
type Asc<T> = Never
```

The ascending order of `T`: by each named field in turn, or by `T`'s own value with no field. `Asc<Person, age>` orders people by age. A key is an integer, a `Bool` or a `String`; `String`s compare bytewise.

## Desc

`type`, at line 11.

```vyrn
type Desc<O> = Never
```

The order `O` reversed.

## Then

`type`, at line 15.

```vyrn
type Then<A, B> = Never
```

The order `A`, then `B` among the values `A` ties. `A` and `B` order one type.

## Elem

`type`, at line 18.

```vyrn
type Elem<O> = Never
```

The type the order `O` compares: `Elem<Asc<Person, age>>` is `Person`.

## Order

`protocol`, at line 22.

```vyrn
protocol Order {}
```

The bound of a type parameter that stands for an order. `Asc`, `Desc` and `Then` satisfy it, and nothing else does.

## before

`fn`, at line 26.

```vyrn
fn before<O: Order>(a: Elem<O>, b: Elem<O>) -> Bool
```

Whether `a` is strictly before `b` under `O`. Two values tie under `O` when neither is before the other.

## sort

`fn`, at line 32.

```vyrn
fn sort<O: Order>(xs: consume Array<Elem<O>>) -> Array<Elem<O>> where sorted<O>(value)
```

`xs` sorted by `O`, stably: values that tie keep their order. An insertion sort, quadratic in the length.

## insertSorted

`fn`, at line 54.

```vyrn
fn insertSorted<O: Order>(
    xs: consume Array<Elem<O>> where sorted<O>(value),
    v: consume Elem<O>,
) -> Array<Elem<O>> where sorted<O>(value)
```

The sorted `xs` with `v` inserted after every value it is not before.

## mergeSorted

`fn`, at line 78.

```vyrn
fn mergeSorted<O: Order>(
    a: consume Array<Elem<O>> where sorted<O>(value),
    b: consume Array<Elem<O>> where sorted<O>(value),
) -> Array<Elem<O>> where sorted<O>(value)
```

The sorted `a` and `b` as one sorted array. Of two values that tie, `a`'s comes first.

## dedupSorted

`fn`, at line 114.

```vyrn
fn dedupSorted<O: Order>(
    xs: consume Array<Elem<O>> where sorted<O>(value),
) -> Array<Elem<O>> where strict<O>(value)
```

The sorted `xs` with each run of values that tie under `O` cut to its first.

## lowerBound

`fn`, at line 137.

```vyrn
fn lowerBound<O: Order>(
    xs: Array<Elem<O>> where sorted<O>(value),
    v: Elem<O>,
) -> Int64 where value >= 0 && value <= xs.length
```

The first position in the sorted `xs` whose value `v` is not after: the count of values before `v`. Binary search.

---

From https://vyrn-lang.github.io/docs/std/order.html — generated by `site/export.vyrn` from the Vyrn repository.
