diff options
Diffstat (limited to 'api')
| -rw-r--r-- | api/api.md | 77 | ||||
| -rw-r--r-- | api/paths.md | 28 | ||||
| -rw-r--r-- | api/paths.yaml | 28 | ||||
| -rw-r--r-- | api/sets.md | 24 | ||||
| -rw-r--r-- | api/tables.md | 27 |
5 files changed, 184 insertions, 0 deletions
@@ -3010,6 +3010,34 @@ follow_symlinks | `Bool` | Whether to follow symbolic links. | `yes` = none ``` +## Path.has_extension + +```tomo +Path.has_extension : func(path: Path, extension: Text -> Bool) +``` + +Return whether or not a path has a given file extension. + +Argument | Type | Description | Default +---------|------|-------------|--------- +path | `Path` | A path. | - +extension | `Text` | A file extension (leading `.` is optional). If empty, the check will test if the file does not have any file extension. | - + +**Return:** Whether or not the path has the given extension. + + +**Example:** +```tomo +>> (/foo.txt).has_extension("txt") += yes +>> (/foo.txt).has_extension(".txt") += yes +>> (/foo.tar.gz).has_extension("gz") += yes +>> (/foo.tar.gz).has_extension("zip") += no + +``` ## Path.is_directory ```tomo @@ -3880,6 +3908,55 @@ t.set("C", 3) = {"A"=1, "B"=2, "C"=3} ``` +## Table.with_fallback + +```tomo +Table.with_fallback : func(t: {K=V}, fallback: {K=V}? -> {K=V}) +``` + +Return a copy of a table with a different fallback table. + +Argument | Type | Description | Default +---------|------|-------------|--------- +t | `{K=V}` | The table whose fallback will be replaced. | - +fallback | `{K=V}?` | The new fallback table value. | - + +**Return:** The original table with a different fallback. + + +**Example:** +```tomo +t := {"A"=1; fallback={"B"=2}} +t2 = t.with_fallback({"B"=3"}) +>> t2["B"] += 3? +t3 = t.with_fallback(none) +>> t2["B"] += none + +``` +## Table.xor + +```tomo +Table.xor : func(a: |T|, b: |T| -> |T|) +``` + +Return set with the elements in one, but not both of the arguments. This is also known as the symmetric difference or disjunctive union. + +Argument | Type | Description | Default +---------|------|-------------|--------- +a | `|T|` | The first set. | - +b | `|T|` | The second set. | - + +**Return:** A set with the symmetric difference of the arguments. + + +**Example:** +```tomo +>> |1, 2, 3|.xor(|2, 3, 4|) += |1, 4| + +``` # Text ## Text.as_c_string diff --git a/api/paths.md b/api/paths.md index ad6b894b..aade9b0f 100644 --- a/api/paths.md +++ b/api/paths.md @@ -489,6 +489,34 @@ follow_symlinks | `Bool` | Whether to follow symbolic links. | `yes` = none ``` +## Path.has_extension + +```tomo +Path.has_extension : func(path: Path, extension: Text -> Bool) +``` + +Return whether or not a path has a given file extension. + +Argument | Type | Description | Default +---------|------|-------------|--------- +path | `Path` | A path. | - +extension | `Text` | A file extension (leading `.` is optional). If empty, the check will test if the file does not have any file extension. | - + +**Return:** Whether or not the path has the given extension. + + +**Example:** +```tomo +>> (/foo.txt).has_extension("txt") += yes +>> (/foo.txt).has_extension(".txt") += yes +>> (/foo.tar.gz).has_extension("gz") += yes +>> (/foo.tar.gz).has_extension("zip") += no + +``` ## Path.is_directory ```tomo diff --git a/api/paths.yaml b/api/paths.yaml index 40813129..1bfe5d6d 100644 --- a/api/paths.yaml +++ b/api/paths.yaml @@ -463,6 +463,34 @@ Path.group: = "root" >> (/non/existent/file).group() = none + +Path.has_extension: + short: check if a path has a given extension + description: > + Return whether or not a path has a given file extension. + return: + type: 'Bool' + description: > + Whether or not the path has the given extension. + args: + path: + type: 'Path' + description: > + A path. + extension: + type: 'Text' + description: > + A file extension (leading `.` is optional). If empty, the check will + test if the file does not have any file extension. + example: | + >> (/foo.txt).has_extension("txt") + = yes + >> (/foo.txt).has_extension(".txt") + = yes + >> (/foo.tar.gz).has_extension("gz") + = yes + >> (/foo.tar.gz).has_extension("zip") + = no Path.is_directory: short: check if a path is a directory diff --git a/api/sets.md b/api/sets.md index b64439c2..8b07cf08 100644 --- a/api/sets.md +++ b/api/sets.md @@ -241,3 +241,27 @@ other | `|T|` | The set of items to remove from the original set. | - = |1| ``` + +# Table +## Table.xor + +```tomo +Table.xor : func(a: |T|, b: |T| -> |T|) +``` + +Return set with the elements in one, but not both of the arguments. This is also known as the symmetric difference or disjunctive union. + +Argument | Type | Description | Default +---------|------|-------------|--------- +a | `|T|` | The first set. | - +b | `|T|` | The second set. | - + +**Return:** A set with the symmetric difference of the arguments. + + +**Example:** +```tomo +>> |1, 2, 3|.xor(|2, 3, 4|) += |1, 4| + +``` diff --git a/api/tables.md b/api/tables.md index 580488f4..26bfe908 100644 --- a/api/tables.md +++ b/api/tables.md @@ -164,3 +164,30 @@ t.set("C", 3) = {"A"=1, "B"=2, "C"=3} ``` +## Table.with_fallback + +```tomo +Table.with_fallback : func(t: {K=V}, fallback: {K=V}? -> {K=V}) +``` + +Return a copy of a table with a different fallback table. + +Argument | Type | Description | Default +---------|------|-------------|--------- +t | `{K=V}` | The table whose fallback will be replaced. | - +fallback | `{K=V}?` | The new fallback table value. | - + +**Return:** The original table with a different fallback. + + +**Example:** +```tomo +t := {"A"=1; fallback={"B"=2}} +t2 = t.with_fallback({"B"=3"}) +>> t2["B"] += 3? +t3 = t.with_fallback(none) +>> t2["B"] += none + +``` |
