Answers a Dictionary built from a List of entries, or from a List of keys and a Function.
Two entries with equal keys collapse into one. The later value wins, and the key keeps the place of its first occurrence. Equality is the keys' own is.
Answers a Dictionary built from a List of entries.
Two entries with equal keys collapse into one. The later value wins, and the key keeps the place of its first occurrence. Equality is the keys' own is.
NameTypeDescription
_List<{ key: KeyType, value: ValueType }>the entries the Dictionary holds
Answers a Dictionary of the given keys, each holding what the Function answers for it.
The Function is asked once for each key, in the order the keys stand in. A key written down twice keeps the place of its first occurrence and holds what the Function answered the second time. The empty List answers the empty Dictionary.
NameTypeDescription
_List<KeyType>the keys the Dictionary holds
valuedBy(_: KeyType) -> ValueTypethe Function answering the value of each key
is<KeyType is Equatable, ValueType is Equatable>( _ other: Dictionary<KeyType, ValueType>,) -> Boolean
Answers whether the two Dictionaries hold the same keys with equal values.
The order the entries stand in does not matter. Each key is found by the keys' own is, and each pair of values is compared by the values' own is. The Method is available whenever the keys and the values conform to Equatable.
NameTypeDescription
_Dictionary<KeyType, ValueType>the Dictionary to compare with
Answers the Dictionary and its entries as a String, in the form ["a" = 1, "b" = 2].
Each key and each value is rendered by its own toString, and a String is quoted: ["a" = "b"]. The empty Dictionary answers [=]. The empty List answers [], so the two are never the same text. The Method is available whenever the keys and the values conform to Printable.
Returns the String representation of the Dictionary.
Answers a new Dictionary with the given key holding the given value.
A key that is already there keeps its place and takes the new value. A key that is not there is added at the end. Equality is the keys' own is. The answer holds the entry that was set, so it is never empty.
NameTypeDescription
_KeyTypethe key to set
toValueTypethe value the key holds
Returns the Dictionary with that entry, which certainly has an entry.
Example
constant stock = ["tea" = 2, "jam" = 1]expect stock::set("tea", to 5)::is(["tea" = 5, "jam" = 1])expect stock::set("tea", to 5)::keys()::is(["tea", "jam"])expect stock::set("milk", to 4)::keys()::is(["tea", "jam", "milk"])
update
on Dictionary<KeyType, ValueType>
Answers a new Dictionary with the given key's value transformed.
update(at:with:) answers the receiver unchanged when the key holds no value. update(at:defaultingTo:with:) transforms the given value in its place.
Returns the Dictionary with the transformed value.
update<KeyType is Equatable>( at key: KeyType, with transform: (_: ValueType) -> ValueType,) -> Dictionary<KeyType, ValueType>
Answers a new Dictionary with the given key's value transformed.
A key that holds no value answers the receiver unchanged, and the transform does not run.
NameTypeDescription
atKeyTypethe key whose value to transform
with(_: ValueType) -> ValueTypethe transform the value is handed to
Returns the Dictionary with the transformed value.
remove<KeyType is Equatable>( atEvery keys: List<KeyType>,) -> Dictionary<KeyType, ValueType>
Answers a new Dictionary without any of the given keys.
A key that is not there changes nothing, and a key written down twice is removed once. The empty List answers the receiver unchanged. The entries that are left keep the order they had. Equality is the keys' own is.
Answers a new Dictionary with its entries ordered by the keys, or by a key read off each entry.
The sort is stable, so entries the order does not tell apart keep the order they had, in either direction. A direction is read where one is taken, and it is #Ascending when a call names none.
Returns the ordered Dictionary.
sort<KeyType is Comparable>( in order: SortOrder = #Ascending,) -> Dictionary<KeyType, ValueType>
Answers a new Dictionary in the given direction, by the keys' own ordering.
The sort is stable. The entry is available whenever the keys conform to Comparable. The direction is #Ascending when a call names none.
NameTypeDescription
inSortOrder = #Ascendingthe direction to order in, #Ascending when it is left out
sort<infer Key is Comparable>( on key: (_: { key: KeyType, value: ValueType }) -> Key, in order: SortOrder = #Ascending,) -> Dictionary<KeyType, ValueType>
Answers a new Dictionary in the given direction of what the key reads off each entry.
The key is read once per entry. The sort is stable, so entries whose keys compare equal keep the order they had. The entry is available whenever what the key answers conforms to Comparable. The direction is #Ascending when a call names none.
NameTypeDescription
on(_: { key: KeyType, value: ValueType }) -> Keythe key each entry is ordered by
inSortOrder = #Ascendingthe direction to order in, #Ascending when it is left out
Answers a new Dictionary with its entries ordered by the keys, or by a key read off each entry.
The sort is stable, so entries the order does not tell apart keep the order they had, in either direction. A direction is read where one is taken, and it is #Ascending when a call names none.
Returns the ordered Dictionary, which certainly has an entry.
sort<infer Key is Comparable>( on key: (_: { key: KeyType, value: ValueType }) -> Key, in order: SortOrder = #Ascending,) -> NonEmptyDictionary<KeyType, ValueType>
Answers a new Dictionary in the given direction of what the key reads off each entry.
The key is read once per entry. The sort is stable, so entries whose keys compare equal keep the order they had. The entry is available whenever what the key answers conforms to Comparable. The direction is #Ascending when a call names none.
NameTypeDescription
on(_: { key: KeyType, value: ValueType }) -> Keythe key each entry is ordered by
inSortOrder = #Ascendingthe direction to order in, #Ascending when it is left out
Returns the ordered Dictionary, which certainly has an entry.
Each type below is a checked refinement: a type with a condition. A value has the type only once the compiler knows the condition holds, and Checked refinements shows how it finds out. Under each one, Tighter here lists the methods above that return a more precise type when called on it. Returned by lists the methods that return it.
NonEmptyDictionary
type NonEmptyDictionary<KeyType, ValueType> = Dictionary<KeyType, ValueType> where @::hasEntries()
A Dictionary proven to have an entry in it, as a checked refinement of Dictionary.
The proof is what lets length answer above zero, and keys, values and entries answer a List with something in it. A Dictionary written down with an entry in it carries the proof. A Dictionary a Program is handed earns it through an if asking hasEntries, and set answers with this Type whatever it was given.