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

# at

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

```una
pub at[T](xs: List[T], index: Int) -> Option[T]
  ensures (result is None) == (index < 0 or index >= xs.len)
```

`Some` of the element at position `index`, counted from 0, and `None` exactly when `index` is below `0` or at least `xs.len`; it never fails (`spec/14 §1`).

## Parameters

- `xs`: the list
- `index`: the position\, from 0

## Returns

`Option[T]`: `Some` of the element at `index`\, and `None` exactly when `index` is below `0` or at least `xs.len`\; it never fails.

## See also

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

## Cost

Time `O(1) index` (ADR 0107).

## Example

`src/shop.una`

```una
module shop

--- The item at a position of a cart, if there is one.
describe(names: List[Text], index: Int) -> Text
=
  when names.at(index: index)
    is Some(name) -> "{index}: {name}"
    is None -> "{index}: no item"

pub main() -> Unit
  uses @console: Console[print]
=
  let names = ["lamp", "desk", "chair"]
  @console.print(describe(names, index: 1))
  @console.print(describe(names, index: 3))
```

`una run .` prints:

```text
1: desk
3: no item
```

## Specification

- [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1)

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).
