> ## Documentation Index
> Fetch the complete documentation index at: https://docs.canton.network/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> If you are building a Canton Network application, start from https://docs.canton.network/appdev/quickstart.md. To run only a local network for your own Daml code, without building the QuickStart demo, see https://docs.canton.network/sdks-tools/development-tools/localnet.md.

# DA.TextMap

> Reference documentation for Daml module DA.TextMap.

Daml module

# DA.TextMap

TextMap - A map is an associative array data type composed of a

Daml

Module
DA.TextMap

Latest release
3.7.5

## Functions

### `fromList`

`fromList` : \[([`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952), `a`)] -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`

Create a map from a list of key/value pairs.

### `fromListWithL`

`fromListWithL` : (`a` -> `a` -> `a`) -> \[([`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952), `a`)] -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`

Create a map from a list of key/value pairs with a combining
function. The combining function is only used when a key appears multiple
times in the list and it takes two arguments: the first one is the new value
being inserted at that key and the second one is the value accumulated so
far at that key.
Examples:

```
>>> fromListWithL (++) [("A", [1]), ("A", [2]), ("B", [2]), ("B", [1]), ("A", [3])]
fromList [("A", [3, 2, 1]), ("B", [1, 2])]
>>> fromListWithL (++) [] == (empty : TextMap [Int])
True
```

### `fromListWithR`

`fromListWithR` : (`a` -> `a` -> `a`) -> \[([`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952), `a`)] -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`

Create a map from a list of key/value pairs like `fromListWithL`
with the combining function flipped. Examples:

```
>>> fromListWithR (++) [("A", [1]), ("A", [2]), ("B", [2]), ("B", [1]), ("A", [3])]
fromList [("A", [1, 2, 3]), ("B", [2, 1])]
>>> fromListWithR (++) [] == (empty : TextMap [Int])
True
```

### `fromListWith`

`fromListWith` : (`a` -> `a` -> `a`) -> \[([`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952), `a`)] -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`

> [!WARNING]
>
> Deprecated: Daml compatibility helper, use 'fromListWithR' instead of 'fromListWith'

### `toList`

`toList` : [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a` -> \[([`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952), `a`)]

Convert the map to a list of key/value pairs where the keys are
in ascending order.

### `empty`

`empty` : [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`

The empty map.

### `size`

`size` : [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a` -> [`Int`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-int-37261)

Number of elements in the map.

### `null`

`null` : [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `v` -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

Is the map empty?

### `lookup`

`lookup` : [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a` -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `a`

Lookup the value at a key in the map.

### `member`

`member` : [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `v` -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

Is the key a member of the map?

### `filter`

`filter` : (`v` -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)) -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `v` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `v`

Filter the `TextMap` using a predicate: keep only the entries where the
value satisfies the predicate.

### `filterWithKey`

`filterWithKey` : ([`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> `v` -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)) -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `v` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `v`

Filter the `TextMap` using a predicate: keep only the entries which
satisfy the predicate.

### `delete`

`delete` : [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`

Delete a key and its value from the map. When the key is not a
member of the map, the original map is returned.

### `singleton`

`singleton` : [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> `a` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`

Create a singleton map.

### `insert`

`insert` : [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> `a` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`

Insert a new key/value pair in the map. If the key is already
present in the map, the associated value is replaced with the
supplied value.

### `insertWith`

`insertWith` : (`v` -> `v` -> `v`) -> [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> `v` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `v` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `v`

Insert a new key/value pair in the map. If the key is already
present in the map, it is combined with the previous value using the given function
`f new_value old_value`.

### `union`

`union` : [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`

The union of two maps, preferring the first map when equal
keys are encountered.

### `merge`

`merge` : ([`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> `a` -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `c`) -> ([`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> `b` -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `c`) -> ([`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> `a` -> `b` -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) `c`) -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `b` -> [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `c`

Merge two maps. `merge f g h x y` applies `f` to all key/value pairs
whose key only appears in `x`, `g` to all pairs whose key only appears
in `y` and `h` to all pairs whose key appears in both `x` and `y`.
In the end, all pairs yielding `Some` are collected as the result.

## Orphan Typeclass Instances

* instance [`Show`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-ghc-show-show-65360) `a` => [`Show`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-ghc-show-show-65360) ([`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`)

* instance [`Eq`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-ghc-classes-eq-22713) `a` => [`Eq`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-ghc-classes-eq-22713) ([`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`)

* instance [`Ord`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-ghc-classes-ord-6395) `a` => [`Ord`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-ghc-classes-ord-6395) ([`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `a`)

* instance [`Semigroup`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-da-internal-prelude-semigroup-78998) ([`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `b`)

* instance [`Monoid`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-da-internal-prelude-monoid-6742) ([`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691) `b`)

* instance [`Functor`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-ghc-base-functor-31205) [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691)

* instance [`Foldable`](https://docs.canton.network/appdev/reference/daml-standard-library/da-foldable#class-da-foldable-foldable-25994) [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691)

* instance [`Traversable`](https://docs.canton.network/appdev/reference/daml-standard-library/da-traversable#class-da-traversable-traversable-18144) [`TextMap`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-textmap-11691)
