Range[T @ Num]
Describes a numeric interval for iteration and slicing.
Inherits from: Iterable[T]
Constructor
Range …
a..b is half-open: it includes a and excludes b.
Open-ended forms keep the missing endpoint as nil internally.
Parameters
| Name | Type | Description |
|---|---|---|
start? |
T |
|
end? |
T |
|
step? |
T |
Methods
(iter)() -> Iter[T]
Iterates the interval. Open-ended ranges require a concrete start.
contains value -> Bool
Tests whether the given value is within the Range interval. For increasing ranges (start < end), checks if value is in [start, end). For decreasing ranges (start > end), checks if value is in (end, start].
Parameters
| Name | Type | Description |
|---|---|---|
value |
T |
the value to check |
Example
# Increasing Range [0, 5)
let r1 = Range 0 5
assert (r1.contains 0)
assert (r1.contains 4)
assert (!r1.contains 5)
# Decreasing Range (0, 5]
let r2 = Range 5 0 -1
assert (r2.contains 5)
assert (r2.contains 1)
assert (!r2.contains 0)
end() -> (T | nil)
The ending value (exclusive), or nil for open-end ranges.
start() -> (T | nil)
The starting value, or nil for open-start ranges.
step() -> (T | nil)
The step size, or nil when unset.