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

NameDescription
ValueTypeThe type of every value stored in the map.

Definition

TYPE Collection.Map(ValueType)
A native, string-keyed reactive collection; it renders to each target's map type.

Example

STATE Collection.Map(Maths.Integer) scores = Collection.Map.Zero
LET Maths.Integer adaScore = Collection.Map.Get scores "ada" 0
An empty map of integer scores; adaScore 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

NameDescription
ValueTypeThe type of the entry's value.

Fields

FieldTypeDescription
keyTextThe entry's key.
valueValueTypeThe value stored under that key.

Definition

TYPE Collection.Map.Entry(ValueType)
  FIELD Text key
  FIELD ValueType value

Example

Collection.Map.EachEntry scores
  INPUT Collection.Map.Entry(Maths.Integer) entry
  Ui.Content.Text entry.key
Each pair arrives as a Collection.Map.Entry; its key and value fields are read with dotted access.

Functions

Collection.Map.EachEntry

Runs a block once for each entry.

Generics

NameDescription
ValueTypeThe type of the values.

Parameters

NameTypeDescription
mapCollection.Map(ValueType)The map to iterate.

Holes

NameReturnsDescription
callbacknothingRun once per entry, each in its own reactive branch keyed by the entry's key.
Inputs
NameTypeDescription
entryCollection.Map.Entry(ValueType)The current key–value pair.

Example

Collection.Map.EachEntry scores
  INPUT Collection.Map.Entry(Maths.Integer) entry
  Ui.Content.Text entry.key
Renders one line per entry; entry.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

NameDescription
ValueTypeThe type of the value being emitted.

Parameters

NameTypeDescription
keyTextThe entry's key.
valueValueTypeThe value to store under it.

Example

  Collection.Map.Emit "ada" 10
Contributes one entry to the map Gather returns. Called outside a Gather it does nothing.

Collection.Map.Entries

The map's pairs as an array.

Generics

NameDescription
ValueTypeThe type of the values.

Parameters

NameTypeDescription
mapCollection.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 scores
Hands you the pairs as an array — ready for Collection.Array.Each, Map and the rest.

Collection.Map.FromEntries

Builds a map from an array of key–value entries.

Generics

NameDescription
ValueTypeThe type of the values.

Parameters

NameTypeDescription
entriesCollection.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 pairs
Turns an array of entries into a keyed map.

Collection.Map.Gather

Builds a map from the entries a callback emits.

Generics

NameDescription
ValueTypeThe type of the values emitted, and of the map built.

Holes

NameReturnsDescription
callbacknothingRun 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" 8
The same gather/emit construction pattern arrays use, keyed by Text.

Collection.Map.Get

The value under a key, falling back to a default when the key is missing.

Generics

NameDescription
ValueTypeThe type of the values.

Parameters

NameTypeDescription
mapCollection.Map(ValueType)The map to read.
keyTextThe key to look up.
defaultValueValueTypeReturned 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
Reads "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

NameDescription
InputTypeThe value type of the input map.
OutputTypeThe value type each result produces, and of the new map.

Parameters

NameTypeDescription
mapCollection.Map(InputType)The map to transform.

Holes

NameReturnsDescription
transformOutputTypeRun once per entry, with the key and value; its result becomes the new value under that key.
Inputs
NameTypeDescription
keyTextThe entry's key.
valueInputTypeThe entry's value.

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 value
Both the key and the value are in scope, so each new value can be built from the whole pair.

Collection.Map.MapValues

A new map with each value transformed, keys unchanged.

Generics

NameDescription
InputTypeThe value type of the input map.
OutputTypeThe value type each result produces, and of the new map.

Parameters

NameTypeDescription
mapCollection.Map(InputType)The map to transform.

Holes

NameReturnsDescription
transformOutputTypeRun once per entry; its result becomes the new value under the same key.
Inputs
NameTypeDescription
valueInputTypeThe current value.

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 score
Turns a map of integer scores into a map of their text renderings, keeping every key.

Collection.Map.OptionalGet

The value under a key as an optional, absent when the key is missing.

Generics

NameDescription
ValueTypeThe type of the values.

Parameters

NameTypeDescription
optionalMapCollection.Optional(Collection.Map(ValueType))The map to read; itself optional.
keyTextThe 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"
Distinguishes "stored zero" from "no value" without needing a fallback.

Collection.Map.Set

A new map with a key set to a value, adding or replacing the entry.

Generics

NameDescription
ValueTypeThe type of the values.

Parameters

NameTypeDescription
mapCollection.Map(ValueType)The starting map.
keyTextThe key to set.
valueValueTypeThe 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" 8
Maps are immutable, so Set returns a fresh map with "lin" stored as 8.

Collection.Map.Zero

An empty map of the value type.

Generics

NameDescription
ValueTypeThe 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
The empty starting point for a map.