---
title: Std.Dict
---

Immutable key-value dictionaries backed by Erlang maps.

## Functions

### new

```saga
fun new : Unit -> Dict k v
```

Creates an empty dictionary.

### from_list

```saga
fun from_list : (pairs: List (k, v)) -> Dict k v where {k: Eq}
```

Creates a dictionary from a list of key-value pairs.

### get

```saga
fun get : (key: k) -> (dict: Dict k v) -> Maybe v where {k: Eq}
```

Returns the value for a key, or Nothing if not present.

### put

```saga
fun put : (key: k) -> (value: v) -> (dict: Dict k v) -> Dict k v where {k: Eq}
```

Inserts or replaces a key-value pair.

### remove

```saga
fun remove : (key: k) -> (dict: Dict k v) -> Dict k v where {k: Eq}
```

Removes a key from the dictionary. Returns the dict unchanged if key is not present.

### member

```saga
fun member : (key: k) -> (dict: Dict k v) -> Bool where {k: Eq}
```

Returns True if the key is present in the dictionary.

### size

```saga
fun size : (dict: Dict k v) -> Int
```

Returns the number of entries in the dictionary.

### is_empty

```saga
fun is_empty : Dict k v -> Bool
```

Returns True if the dictionary has no entries.

### keys

```saga
fun keys : (dict: Dict k v) -> List k
```

Returns all keys as a list.

### values

```saga
fun values : (dict: Dict k v) -> List v
```

Returns all values as a list.

### to_list

```saga
fun to_list : (dict: Dict k v) -> List (k, v)
```

Converts the dictionary to a list of key-value pairs.

### map

```saga
fun map : (f: v -> v2) -> (dict: Dict k v) -> Dict k v2
```

Applies a function to every value, returning a new dictionary.

### filter

```saga
fun filter : (pred: k -> v -> Bool) -> (dict: Dict k v) -> Dict k v
```

Returns a dictionary containing only entries where the predicate returns True.

### fold

```saga
fun fold : (f: a -> k -> v -> a) -> (init: a) -> (dict: Dict k v) -> a
```

Folds over all entries, left to right.

### merge

```saga
fun merge : (base: Dict k v) -> (overrides: Dict k v) -> Dict k v where {k: Eq}
```

Merges two dictionaries. Values from the overrides dict win on key conflicts.

### update

```saga
fun update : (key: k) -> (f: v -> v) -> (dict: Dict k v) -> Dict k v where {k: Eq}
```

Updates the value at a key by applying a function. No-op if key is not present.

