aboutsummaryrefslogtreecommitdiff
path: root/docs/arrays.md
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-12-19 13:50:35 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-12-19 13:50:35 -0500
commitb0faa5adc2c5f56ae50cf21f855fa6805db926cf (patch)
treef79e21230108b45843c0bf21c32b08d814802917 /docs/arrays.md
parent1db70d46c62c9478ea84ccff204fb315136e518c (diff)
Add Text:from()/to() and Array:slice() for symmetry
Diffstat (limited to 'docs/arrays.md')
-rw-r--r--docs/arrays.md32
1 files changed, 32 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:**