diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-19 00:23:02 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-19 00:23:02 -0400 |
| commit | 67e8f2dea0d4eec20a839d47f1fa6302a4a5f733 (patch) | |
| tree | 3f9d28687b6ac824b5676c963ef9964ac4857c4a /docs/ranges.md | |
| parent | 8363d53bd27c621cb342fea15736a3b11231f2a4 (diff) | |
Move docs into one folder
Diffstat (limited to 'docs/ranges.md')
| -rw-r--r-- | docs/ranges.md | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/docs/ranges.md b/docs/ranges.md new file mode 100644 index 00000000..4771bd58 --- /dev/null +++ b/docs/ranges.md @@ -0,0 +1,65 @@ +# Ranges + +Ranges are Tomo's way to do iteration over numeric ranges. Ranges are typically +created using the `Int.to()` method like so: `5:to(10)`. Ranges are +*inclusive*. + +```tomo +>> [i for i in 3:to(5)] += [3, 4, 5] +``` + +--- + +## Range Methods + +### `reversed` + +**Description:** +Returns a reversed copy of the range. + +**Usage:** +```tomo +reversed(range: Range) -> Range +``` + +**Parameters:** + +- `range`: The range to be reversed. + +**Returns:** +A new `Range` with the order of elements reversed. + +**Example:** +```tomo +>> 1:to(5):reversed() += Range(first=5, last=1, step=-1) +``` + +--- + +### `by` + +**Description:** +Creates a new range with a specified step value. + +**Usage:** +```tomo +by(range: Range, step: Int) -> Range +``` + +**Parameters:** + +- `range`: The original range. +- `step`: The step value to be used in the new range. + +**Returns:** +A new `Range` that increments by the specified step value. + +**Example:** +```tomo +>> 1:to(5):by(2) += Range(first=1, last=5, step=2) +``` + +--- |
