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

# append

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

```una
pub append[T](xs: List[T], item: T) -> List[T]
  ensures result.len == xs.len + 1
```

`xs` with `item` added after its last element (`spec/14 §1`).

## Parameters

- `xs`: the list
- `item`: the element to add

## Returns

`List[T]`: `xs` with `item` after its last element\; one element longer than `xs`.

## See also

[`set`](https://una-lang.org/en/docs/std/prelude/set/) (edition 0.2 on)

## Cost

Time `amortized O(1) append, O(n) copy when the list is shared` (ADR 0107), where:

- `n`: the length of `xs`

## Example

`src/shop.una`

```una
module shop

--- A cart with one more item.
pub main() -> Unit
  uses @console: Console[print]
=
  let cart = ["lamp"].append(item: "chair")
  @console.print(join(cart, separator: ", "))
  @console.print("{cart.len} items")
```

`una run .` prints:

```text
lamp, chair
2 items
```

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