diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/arrays.md | 32 | ||||
| -rw-r--r-- | docs/text.md | 64 |
2 files changed, 96 insertions, 0 deletions
diff --git a/docs/arrays.md b/docs/arrays.md index ce1c47df..76372cb9 100644 --- a/docs/arrays.md +++ b/docs/arrays.md @@ -816,6 +816,38 @@ A new array with shuffled elements. --- +### `slice` + +**Description:** +Returns a slice of the array spanning the given indices (inclusive). + +**Signature:** +```tomo +func slice(arr: [T], from: Int, to: Int -> [T]) +``` + +**Parameters:** + +- `arr`: The original array. +- `from`: The first index to include. +- `to`: The last index to include. + +**Returns:** +A new array spanning the given indices. Note: negative indices are counted from +the back of the array, so `-1` refers to the last element, `-2` the +second-to-last, and so on. + +**Example:** +```tomo +>> [10, 20, 30, 40, 50]:slice(2, 4) += [20, 30, 40] + +>> [10, 20, 30, 40, 50]:slice(-3, -2) += [30, 40] +``` + +--- + ### `sort` **Description:** diff --git a/docs/text.md b/docs/text.md index 463a2336..ecf32240 100644 --- a/docs/text.md +++ b/docs/text.md @@ -746,6 +746,38 @@ Note: if `text` or `pattern` is empty, an empty array will be returned. --- +## `from` + +**Description:** +Get a slice of the text, starting at the given position. + +**Signature:** +```tomo +func from(text: Text, first: Int -> Text) +``` + +**Parameters:** + +- `text`: The text to be sliced. +- `frist`: The index of the first grapheme cluster to include (1-indexed). + +**Returns:** +The text from the given grapheme cluster to the end of the text. Note: a +negative index counts backwards from the end of the text, so `-1` refers to the +last cluster, `-2` the second-to-last, etc. Slice ranges will be truncated to +the length of the string. + +**Example:** +```tomo +>> "hello":from(2) += "ello" + +>> "hello":from(-2) += "lo" +``` + +--- + ## `has` **Description:** @@ -1217,6 +1249,38 @@ The text in title case. --- +## `to` + +**Description:** +Get a slice of the text, ending at the given position. + +**Signature:** +```tomo +func to(text: Text, last: Int -> Text) +``` + +**Parameters:** + +- `text`: The text to be sliced. +- `last`: The index of the last grapheme cluster to include (1-indexed). + +**Returns:** +The text up to and including the given grapheme cluster. Note: a negative index +counts backwards from the end of the text, so `-1` refers to the last cluster, +`-2` the second-to-last, etc. Slice ranges will be truncated to the length of +the string. + +**Example:** +```tomo +>> "goodbye":to(3) += "goo" + +>> "goodbye":to(-2) += "goodby" +``` + +--- + ## `trim` **Description:** |
