Modules · Data · Collection · Map
Collection.Map
A reactive dictionary of values, each stored under a Text key. Like arrays, maps are immutable: Set returns a new map. Read with Get or OptionalGet, walk every pair with EachEntry, and reshape values with MapValues and MapEntries.
Contents
Types
Functions
Types
Collection.Map
A reactive dictionary: values of one type, each stored under a Text key. Backed by the target's native map. Read a value with Get or OptionalGet, walk every pair with EachEntry, or pull the pairs out as an array with Entries.
Generics
| Name | Description |
|---|---|
ValueType | The type of every value stored in the map. |
Definition
TYPE Collection.Map(ValueType)Example
STATE Collection.Map(Maths.Integer) scores = Collection.Map.Zero
LET Maths.Integer adaScore = Collection.Map.Get scores "ada" 0adaScore falls back to 0 until a value is stored under "ada".Collection.Map.Entry
A single key–value pair from a map. Entries returns an array of these, and EachEntry hands one to its callback per pair.
Generics
| Name | Description |
|---|---|
ValueType | The type of the entry's value. |
Fields
| Field | Type | Description |
|---|---|---|
key | Text | The entry's key. |
value | ValueType | The value stored under that key. |
Definition
TYPE Collection.Map.Entry(ValueType)
FIELD Text key
FIELD ValueType valueExample
Collection.Map.EachEntry scores
INPUT Collection.Map.Entry(Maths.Integer) entry
Ui.Content.Text entry.keyCollection.Map.Entry; its key and value fields are read with dotted access.Functions
Collection.Map.EachEntry
Runs a block once for each entry.
Generics
| Name | Description |
|---|---|
ValueType | The type of the values. |
Parameters
| Name | Type | Description |
|---|---|---|
map | Collection.Map(ValueType) | The map to iterate. |
Holes
| Name | Returns | Description | ||||||
|---|---|---|---|---|---|---|---|---|
callback | nothing | Run once per entry, each in its own reactive branch keyed by the entry's key.Inputs
|
Example
Collection.Map.EachEntry scores
INPUT Collection.Map.Entry(Maths.Integer) entry
Ui.Content.Text entry.keyentry.key and entry.value read the pair.Collection.Map.Emit
Adds one key–value entry to the map being built by the enclosing Gather.
Generics
| Name | Description |
|---|---|
ValueType | The type of the value being emitted. |
Parameters
| Name | Type | Description |
|---|---|---|
key | Text | The entry's key. |
value | ValueType | The value to store under it. |
Example
Collection.Map.Emit "ada" 10Gather returns. Called outside a Gather it does nothing.Collection.Map.Entries
The map's pairs as an array.
Generics
| Name | Description |
|---|---|
ValueType | The type of the values. |
Parameters
| Name | Type | Description |
|---|---|---|
map | Collection.Map(ValueType) | The map to read. |
Returns
Returns Collection.Array(Collection.Map.Entry(ValueType)) — one Collection.Map.Entry per key.
Example
LET Collection.Array(Collection.Map.Entry(Maths.Integer)) pairs = Collection.Map.Entries scoresCollection.Array.Each, Map and the rest.Collection.Map.FromEntries
Builds a map from an array of key–value entries.
Generics
| Name | Description |
|---|---|
ValueType | The type of the values. |
Parameters
| Name | Type | Description |
|---|---|---|
entries | Collection.Array(Collection.Map.Entry(ValueType)) | The pairs to load into the map. |
Returns
Returns Collection.Map(ValueType) — a map holding every entry; later entries win on duplicate keys.
Example
LET Collection.Map(Maths.Integer) scores = Collection.Map.FromEntries pairsCollection.Map.Gather
Builds a map from the entries a callback emits.
Generics
| Name | Description |
|---|---|
ValueType | The type of the values emitted, and of the map built. |
Holes
| Name | Returns | Description |
|---|---|---|
callback | nothing | Run once; each call it makes to Collection.Map.Emit adds one entry. Later keys replace earlier ones. |
Returns
Returns Collection.Map(ValueType) — the map of everything the callback emitted.
Example
LET Collection.Map(Maths.Integer) scores = Collection.Map.Gather
Collection.Map.Emit "ada" 10
Collection.Map.Emit "lin" 8Text.Collection.Map.Get
The value under a key, falling back to a default when the key is missing.
Generics
| Name | Description |
|---|---|
ValueType | The type of the values. |
Parameters
| Name | Type | Description |
|---|---|---|
map | Collection.Map(ValueType) | The map to read. |
key | Text | The key to look up. |
defaultValue | ValueType | Returned when the key is absent. |
Returns
Returns ValueType — the stored value, or defaultValue when the key is missing.
Example
LET Maths.Integer ada = Collection.Map.Get scores "ada" 0"ada", or 0 when nothing is stored there.Collection.Map.MapEntries
A new map built by transforming each key–value pair into a new value.
Generics
| Name | Description |
|---|---|
InputType | The value type of the input map. |
OutputType | The value type each result produces, and of the new map. |
Parameters
| Name | Type | Description |
|---|---|---|
map | Collection.Map(InputType) | The map to transform. |
Holes
| Name | Returns | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
transform | OutputType | Run once per entry, with the key and value; its result becomes the new value under that key.Inputs
|
Returns
Returns Collection.Map(OutputType) — a new map keyed as before, with values derived from key and value.
Example
LET Collection.Map(Text) rows = Collection.Map.MapEntries scores
INPUT Text key
INPUT Maths.Integer value
Text.Append key Maths.Integer.ToString valueCollection.Map.MapValues
A new map with each value transformed, keys unchanged.
Generics
| Name | Description |
|---|---|
InputType | The value type of the input map. |
OutputType | The value type each result produces, and of the new map. |
Parameters
| Name | Type | Description |
|---|---|---|
map | Collection.Map(InputType) | The map to transform. |
Holes
| Name | Returns | Description | ||||||
|---|---|---|---|---|---|---|---|---|
transform | OutputType | Run once per entry; its result becomes the new value under the same key.Inputs
|
Returns
Returns Collection.Map(OutputType) — a new map with the same keys and transformed values.
Example
LET Collection.Map(Text) labels = Collection.Map.MapValues scores
INPUT Maths.Integer score
Maths.Integer.ToString scoreCollection.Map.OptionalGet
The value under a key as an optional, absent when the key is missing.
Generics
| Name | Description |
|---|---|
ValueType | The type of the values. |
Parameters
| Name | Type | Description |
|---|---|---|
optionalMap | Collection.Optional(Collection.Map(ValueType)) | The map to read; itself optional. |
key | Text | The key to look up. |
Returns
Returns Collection.Optional(ValueType) — present with the value, or absent when the map or the key is missing.
Example
LET Collection.Optional(Maths.Integer) maybeAda = Collection.Map.OptionalGet scores "ada"Collection.Map.Set
A new map with a key set to a value, adding or replacing the entry.
Generics
| Name | Description |
|---|---|
ValueType | The type of the values. |
Parameters
| Name | Type | Description |
|---|---|---|
map | Collection.Map(ValueType) | The starting map. |
key | Text | The key to set. |
value | ValueType | The value to store. |
Returns
Returns Collection.Map(ValueType) — a new map with the entry set; the original is unchanged.
Example
LET Collection.Map(Maths.Integer) updated = Collection.Map.Set scores "lin" 8Set returns a fresh map with "lin" stored as 8.Collection.Map.Zero
An empty map of the value type.
Generics
| Name | Description |
|---|---|
ValueType | The value type of the new map. |
Returns
Returns Collection.Map(ValueType) — a new map with no entries.
Example
STATE Collection.Map(Maths.Integer) scores = Collection.Map.Zero