> ## Documentation Index
> Fetch the complete documentation index at: https://validity-kt.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Maps

> Size, keys and values of a Map.

The constraints of a `Map` as a whole. Their size messages count entries, not items, so they have messages of their
own (`minEntries`, `maxEntries`, `entries`, `entriesBetween`). To check every key or value, use
[`eachKey` and `eachValue`](https://validity-kt.dev/guides/collections-and-maps#maps).

> [!NOTE]
>
> A `null` argument checks nothing. A rule that reads a value that may be missing, such as `max(customer.limit)`,
> never fails because of it: `required` on that value reports it once.

```kotlin Translations.kt theme={null}
private val LANGUAGES = setOf("en", "pt", "es")

data class Translations(
    val titles: Map<String, String>?
) : Validatable {
    override fun validation() = validation {
        ::titles required {
            containsKey("en")
            onlyKeys(LANGUAGES)
            eachValue { maxLength(80) }
        }
    }
}
```

| Constraint | Checks |
| - | - |
| [`minSize`](#minsize) | Has at least `min` entries. |
| [`maxSize`](#maxsize) | Has at most `max` entries. |
| [`size`](#size) | Has exactly `size` entries. |
| [`sizeBetween`](#sizebetween) | Has between `min` and `max` entries, both included. |
| [`notEmpty`](#notempty) | Has at least one entry. |
| [`empty`](#empty) | Has no entries. |
| [`containsKey`](#containskey) | Has the key `key`. |
| [`containsKeys`](#containskeys) | Has every one of `keys`. |
| [`notContainsKey`](#notcontainskey) | Does not have the key `key`. |
| [`onlyKeys`](#onlykeys) | Every key of the map is one of `keys`. |
| [`containsValue`](#containsvalue) | Has `value` as the value of some entry. |

## How many

### `minSize`

`minSize(min)` on `Map`

Checks that the map has at least `min` entries.

**Code** `minSize`· **Message** `must have at least {min} entries` · **Change it** `minEntries = "…"`

### `maxSize`

`maxSize(max)` on `Map`

Checks that the map has at most `max` entries.

**Code** `maxSize`· **Message** `must have at most {max} entries` · **Change it** `maxEntries = "…"`

### `size`

`size(size)` on `Map`

Checks that the map has exactly `size` entries.

**Code** `size`· **Message** `must have exactly {size} entries` · **Change it** `entries = "…"`

### `sizeBetween`

`sizeBetween(min, max)` on `Map`

Checks that the map has between `min` and `max` entries, both included.

**Code** `sizeBetween`· **Message** `must have between {min} and {max} entries` · **Change it** `entriesBetween = "…"`

### `notEmpty`

`notEmpty()` on `Map`

Checks that the map has at least one entry.

**Code** `notEmpty`· **Message** `must not be empty` · **Change it** `notEmpty = "…"`

### `empty`

`empty()` on `Map`

Checks that the map has no entries.

**Code** `empty`· **Message** `must be empty` · **Change it** `empty = "…"`

## Keys and values

### `containsKey`

`containsKey(key)` on `Map`

Checks that the map has the key `key`.

**Code** `containsKey`· **Message** `must contain the key {key}` · **Change it** `containsKey = "…"`

### `containsKeys`

`containsKeys(keys)` on `Map`

Checks that the map has every one of `keys`.

**Code** `containsKeys`· **Message** `must contain the keys {keys}` · **Change it** `containsKeys = "…"`

### `notContainsKey`

`notContainsKey(key)` on `Map`

Checks that the map does not have the key `key`.

**Code** `notContainsKey`· **Message** `must not contain the key {key}` · **Change it** `notContainsKey = "…"`

### `onlyKeys`

`onlyKeys(keys)` on `Map`

Checks that every key of the map is one of `keys`.

Not every key of `keys` has to be there. Combine it with `containsKeys` for that.

**Code** `onlyKeys`· **Message** `must contain only the keys {keys}` · **Change it** `onlyKeys = "…"`

### `containsValue`

`containsValue(value)` on `Map`

Checks that the map has `value` as the value of some entry.

**Code** `containsValue`· **Message** `must contain the value {other}` · **Change it** `containsValue = "…"`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.