diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-19 14:35:34 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-19 14:35:34 -0400 |
| commit | 67fd3c725e6511adf70345f0733ec0b948477a11 (patch) | |
| tree | 913d9f30d8ce3614a9ae3715281f8804323b24ff /docs/tables.md | |
| parent | 0974d632c3dda7874f01c58bfc342b73cd1634a4 (diff) | |
Make API documentation into YAML files and autogenerate markdown files
and manpages from those.
Diffstat (limited to 'docs/tables.md')
| -rw-r--r-- | docs/tables.md | 167 |
1 files changed, 2 insertions, 165 deletions
diff --git a/docs/tables.md b/docs/tables.md index d83a678b..2f07436a 100644 --- a/docs/tables.md +++ b/docs/tables.md @@ -150,169 +150,6 @@ Table iteration operates over the value of the table when the loop began, so modifying the table during iteration is safe and will not result in the loop iterating over any of the new values. -## Table Methods +# API -- [`func clear(t:&{K=V})`](#clear) -- [`func get(t:{K=V}, key: K -> V?)`](#get) -- [`func get_or_set(t:&{K=V}, key: K, default: V -> V)`](#get_or_set) -- [`func has(t:{K=V}, key: K -> Bool)`](#has) -- [`func remove(t:{K=V}, key: K -> Void)`](#remove) -- [`func set(t:{K=V}, key: K, value: V -> Void)`](#set) - ---- - -### `clear` -Removes all key-value pairs from the table. - -```tomo -func clear(t:&{K=V}) -``` - -- `t`: The reference to the table. - -**Returns:** -Nothing. - -**Example:** -```tomo ->> t.clear() -``` - ---- - -### `get` -Retrieves the value associated with a key, or returns `none` if the key is not present. -**Note:** default values for the table are ignored. - -```tomo -func get(t:{K=V}, key: K -> V?) -``` - -- `t`: The table. -- `key`: The key whose associated value is to be retrieved. - -**Returns:** -The value associated with the key or `none` if the key is not found. - -**Example:** -```tomo ->> t := {"A"=1, "B"=2} ->> t.get("A") -= 1? - ->> t.get("????") -= none - ->> t.get("A")! -= 1 - ->> t.get("????") or 0 -= 0 -``` - ---- - -### `get_or_set` -If the given key is in the table, return the associated value. Otherwise, -insert the given default value into the table and return it. - -**Note:** If no default value is provided explicitly, but the table has a -default value associated with it, the table's default value will be used. - -**Note:** The default value is only evaluated if the key is missing. - -```tomo -func get_or_set(t: &{K=V}, key: K, default: V -> V?) -``` - -- `t`: The table. -- `key`: The key whose associated value is to be retrieved. -- `default`: The default value to insert and return if the key is not present in the table. - -**Returns:** -Either the value associated with the key (if present) or the default value. The -table will be mutated if the key is not already present. - -**Example:** -```tomo ->> t := &{"A"=@[1, 2, 3]; default=@[]} ->> t.get_or_set("A").insert(4) ->> t.get_or_set("B").insert(99) ->> t -= &{"A"=@[1, 2, 3, 4], "B"=@[99]} - ->> t.get_or_set("C", @[0, 0, 0]) -= @[0, 0, 0] ->> t -= &{"A"=@[1, 2, 3, 4], "B"=@[99], "C"=@[0, 0, 0]} -``` - ---- - -### `has` -Checks if the table contains a specified key. - -```tomo -func has(t:{K=V}, key: K -> Bool) -``` - -- `t`: The table. -- `key`: The key to check for presence. - -**Returns:** -`yes` if the key is present, `no` otherwise. - -**Example:** -```tomo ->> {"A"=1, "B"=2}.has("A") -= yes ->> {"A"=1, "B"=2}.has("xxx") -= no -``` - ---- - -### `remove` -Removes the key-value pair associated with a specified key. - -```tomo -func remove(t:{K=V}, key: K -> Void) -``` - -- `t`: The reference to the table. -- `key`: The key of the key-value pair to remove. - -**Returns:** -Nothing. - -**Example:** -```tomo -t := {"A"=1, "B"=2} -t.remove("A") ->> t -= {"B"=2} -``` - ---- - -### `set` -Sets or updates the value associated with a specified key. - -```tomo -func set(t:{K=V}, key: K, value: V -> Void) -``` - -- `t`: The reference to the table. -- `key`: The key to set or update. -- `value`: The value to associate with the key. - -**Returns:** -Nothing. - -**Example:** -```tomo -t := {"A"=1, "B"=2} -t.set("C", 3) ->> t -= {"A"=1, "B"=2, "C"=3} -``` +[API documentation](../api/tables.md) |
