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

# min

A function of the prelude, in scope in every module. Edition 0.1 and later.

## Edition 0.1

```una
pub min(a: Int, b: Int) -> Int
  ensures result <= a and result <= b and (result == a or result == b)
```

The smaller of `a` and `b`; in edition 0.2 and later, of any type with `Ord` (`spec/14 §1`, `spec/20 §6`).

## Edition 0.2 and later

```una
pub min[T: Ord](a: T, b: T) -> T
  ensures result <= a and result <= b and (result == a or result == b)
```

The smaller of `a` and `b`; in edition 0.2 and later, of any type with `Ord` (`spec/14 §1`, `spec/20 §6`).

In editions 0.2, 0.3, 0.4, 0.5. In edition 0.1: `min(a: Int, b: Int) -> Int`\: integers only.

## Parameters

- `a`: a value
- `b`: another value of the same type

## Returns

`T`: the smaller of `a` and `b`\: `result <= a`\, `result <= b`\, and it is one of them.

## See also

[`max`](https://una-lang.org/en/docs/std/prelude/max/)

## Example

`src/shop.una`

```una
module shop

--- The price to charge, the lower of the list price and the sale price, and the first of two
--- names in the order of their scalar values.
pub main() -> Unit
  uses @console: Console[print]
=
  let price = min(1999, b: 1499)
  @console.print("{price} cents")
  let first = min("Desk lamp", b: "Chair")
  @console.print(first)
```

`una run .` prints:

```text
1499 cents
Chair
```

## Specification

- [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1)
- [`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).
