aboutsummaryrefslogtreecommitdiff
path: root/docs/ranges.md
blob: 4771bd58f91e8104103182db48bd0dda476858bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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)
```

---