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

# map

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

## Edition 0.1

```una
pub map[T, U](xs: List[T], each: fn(T) -> U) -> List[U]
  ensures result.len == xs.len
```

The list of `each(x)` for each element `x` of `xs`, in the order of `xs`; `each` is called from the first element to the last, at most once per element. In edition 0.2 and later it takes an effectful and failing `each`, and stops at the first failure (`spec/14 §1`).

## Edition 0.2 and later

```una
pub map[T, U](xs: List[T], each: fn(T) -> U) -> List[U]
  ensures result.len == xs.len
  uses of each
  fails of each
```

The list of `each(x)` for each element `x` of `xs`, in the order of `xs`; `each` is called from the first element to the last, at most once per element. In edition 0.2 and later it takes an effectful and failing `each`, and stops at the first failure (`spec/14 §1`).

In editions 0.2, 0.3, 0.4, 0.5. In edition 0.1: `each` has no effects and cannot fail\: the declaration has no `uses of each` or `fails of each`.

## Parameters

- `xs`: the list
- `each`: what each element becomes

## Returns

`List[U]`: `each(x)` for each element `x` of `xs`\, in order\; as many as `xs`.

## Effects

Those of `each`: it calls `each` from the first element on\, at most once per element\, has the effects of `each`\, and stops at the first failure of `each`\, which becomes its own.

## See also

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

## Example

`src/shop.una`

```una
module shop

--- The names of a cart in upper case.
pub main() -> Unit
  uses @console: Console[print]
=
  let names = ["lamp", "desk"].map(each: fn(n) -> n.to_upper())
  @console.print(join(names, separator: ", "))
```

`una run .` prints:

```text
LAMP, DESK
```

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