mirror of
https://github.com/gechandesu/ranges.git
synced 2026-03-25 19:43:24 +03:00
feat: add bounds(), make Range private back
This commit is contained in:
9
ranges.v
9
ranges.v
@@ -3,9 +3,7 @@ module ranges
|
|||||||
import strconv
|
import strconv
|
||||||
import math.big
|
import math.big
|
||||||
|
|
||||||
@[noinit]
|
struct Range[T] {
|
||||||
pub struct Range[T] {
|
|
||||||
pub:
|
|
||||||
start T
|
start T
|
||||||
end T
|
end T
|
||||||
step T
|
step T
|
||||||
@@ -31,6 +29,11 @@ pub fn (mut r Range[T]) reset() {
|
|||||||
r.cur = r.start
|
r.cur = r.start
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bounds returns the start, end and step values of range.
|
||||||
|
pub fn (r Range[T]) bounds() (T, T, T) {
|
||||||
|
return r.start, r.end, r.step
|
||||||
|
}
|
||||||
|
|
||||||
// with_step returns copy of the range with new step value.
|
// with_step returns copy of the range with new step value.
|
||||||
pub fn (r Range[T]) with_step[T](step T) Range[T] {
|
pub fn (r Range[T]) with_step[T](step T) Range[T] {
|
||||||
return Range[T]{
|
return Range[T]{
|
||||||
|
|||||||
@@ -179,3 +179,11 @@ fn test_range_new_with_step() {
|
|||||||
}
|
}
|
||||||
assert result == [0, 2, 4]
|
assert result == [0, 2, 4]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_range_bounds() {
|
||||||
|
r := ranges.range(0, 10, 2)
|
||||||
|
a, b, c := r.bounds()
|
||||||
|
assert a == 0
|
||||||
|
assert b == 10
|
||||||
|
assert c == 2
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user