Documentation ¶
Overview ¶
Package r provides improved Python-like range() experience for Go.
Usage:
| normal style | import "github.com/is5/r" | | ------------------------------------- | ----------------------------------------- | | for i := 0; i < 10; i++ {...} | for i := range r.N(10) {...} | | for i := 1; i <= 10; i++ {...} | for _, i := range r.R(1, 10) {...} | | for i := 30; i >= 20; i-- {...} | for _, i := range r.R(30, 20) {...} | | for i := 10; i <= 100; i += 5 {...} | for _, i := range r.S(10, 100, 5) {...} | | for i := 300; i >= 200; i -= 10 {...} | for _, i := range r.S(300, 200, 10) {...} |
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func N ¶
func N(size int) (seq []empty)
N returns a slice of 0-sized elements, suitable for ranging over.
Example ¶
package main import ( "fmt" "github.com/is5/r" ) func main() { for i := range r.N(10) { fmt.Print(i, " ") } }
Output: 0 1 2 3 4 5 6 7 8 9
func R ¶
R returns a slice of sequential numbers within a specified range. both start and end are inclusive.
Example ¶
package main import ( "fmt" "github.com/is5/r" ) func main() { for _, i := range r.R(1, 10) { fmt.Print(i, " ") } }
Output: 1 2 3 4 5 6 7 8 9 10
func S ¶
S returns a slice of consecutive numbers within a specified range, incremented or decremented by the step.
step should be positive. it panics if step is negative or zero.
Example ¶
package main import ( "fmt" "github.com/is5/r" ) func main() { for _, i := range r.S(10, 100, 5) { fmt.Print(i, " ") } }
Output: 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.