(265 lines)
4 Removes all key-value pairs from the table.8 Nothing.13 The reference to the table.15 t := &{"A":1}16 t.clear()17 assert t[] == {}22 Return a table whose key/value pairs correspond to keys only present in one23 table, but not the other.27 A table containing the common key/value pairs whose keys only appear in28 one table.33 The base table.37 The other table.39 t1 := {"A": 1, "B": 2, "C": 3}40 t2 := {"B": 2, "C":30, "D": 40}41 assert t1.difference(t2) == {"A": 1, "D": 40}46 Retrieves the value associated with a key, or returns `none` if the key is not present.48 Default values for the table are ignored.52 The value associated with the key or `none` if the key is not found.57 The table.61 The key whose associated value is to be retrieved.63 t := {"A": 1, "B": 2}64 assert t.get("A") == 165 assert t.get("????") == none66 assert t.get("A")! == 167 assert t.get("????") or 0 == 072 If the given key is in the table, return the associated value. Otherwise,73 insert the given default value into the table and return it.75 If no default value is provided explicitly, but the table has a76 default value associated with it, the table's default value will be used.78 The default value is only evaluated if the key is missing.82 Either the value associated with the key (if present) or the default value. The83 table will be mutated if the key is not already present.88 The table.92 The key whose associated value is to be retrieved.96 The default value to insert and return if the key is not present in the table.98 t := &{"A": @[1, 2, 3]; default=@[]}99 t.get_or_set("A").insert(4)100 t.get_or_set("B").insert(99)101 assert t["A"][] == [1, 2, 3, 4]102 assert t["B"][] == [99]103 assert t.get_or_set("C", @[0, 0, 0])[] == [0, 0, 0]108 Checks if the table contains a specified key.112 `yes` if the key is present, `no` otherwise.117 The table.121 The key to check for presence.123 assert {"A": 1, "B": 2}.has("A") == yes124 assert {"A": 1, "B": 2}.has("xxx") == no129 Return a table with only the matching key/value pairs that are common to130 both tables.134 A table containing the common key/value pairs shared between two tables.139 The base table.143 The other table.145 t1 := {"A": 1, "B": 2, "C": 3}146 t2 := {"B": 2, "C":30, "D": 40}147 assert t1.intersection(t2) == {"B": 2}152 Removes the key-value pair associated with a specified key.156 Nothing.161 The reference to the table.165 The key of the key-value pair to remove.167 t := &{"A": 1, "B": 2}168 t.remove("A")169 assert t == {"B": 2}174 Sets or updates the value associated with a specified key.178 Nothing.183 The reference to the table.187 The key to set or update.191 The value to associate with the key.193 t := &{"A": 1, "B": 2}194 t.set("C", 3)195 assert t == {"A": 1, "B": 2, "C": 3}200 Return a copy of a table with values added from another table204 The original table, but with values from the other table added.209 The base table.213 The other table from which new key/value pairs will be added.215 t := {"A": 1, "B": 2}216 assert t.with({"B": 20, "C": 30}) == {"A": 1, "B": 20, "C": 30}221 Return a copy of a table, but without any of the exact key/value pairs222 found in the other table.224 Only exact key/value pairs will be discarded. Keys with a non-matching225 value will be kept.229 The original table, but without the key/value pairs from the other table.234 The base table.238 The other table whose key/value pairs will be omitted.240 t := {"A": 1, "B": 2, "C": 3}241 assert t.without({"B": 2, "C": 30, "D": 40}) == {"A": 1, "C": 3}246 Return a copy of a table with a different fallback table.250 The original table with a different fallback.255 The table whose fallback will be replaced.259 The new fallback table value.261 t := {"A": 1; fallback={"B": 2}}262 t2 := t.with_fallback({"B": 3})263 assert t2["B"] == 3264 t3 := t.with_fallback(none)265 assert t3["B"] == none