1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 23:22:28 +08:00

feat: add RangeWithStep function

This commit is contained in:
dudaodong
2023-03-06 18:05:58 +08:00
parent 28d0428b50
commit 51a6912eb3
3 changed files with 50 additions and 0 deletions

View File

@@ -200,3 +200,19 @@ func Range[T constraints.Integer | constraints.Float](start T, count int) []T {
return result
}
// RangeWithStep creates a slice of numbers from start to end with specified step.
// Play: todo
func RangeWithStep[T constraints.Integer | constraints.Float](start, end, step T) []T {
result := []T{}
if start >= end || step == 0 {
return result
}
for i := start; i < end; i += step {
result = append(result, i)
}
return result
}