Skip to content

dushaoshuai/goloop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 Cannot retrieve latest commit at this time.

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goloop

Go Reference

goloop tries to facilitate looping in Go.

Download/Install

go get -u github.com/dushaoshuai/goloop

Quick Start

Replace this trivial code:

for i := 0; i < 10; i++ {
	fmt.Println(i)
}

with:

for i := range goloop.Repeat(10) {
	fmt.Println(i)
}

Break the loop when certain conditions are met:

for i := range goloop.RepeatWithBreak(10) {
	fmt.Println(i.I)
	if i.I == 5 {
		i.Break()
	}
}

Range over a sequence of integers:

for i := range goloop.Range(3, 26, 5) {
    fmt.Println(i.I)
    if i.I >= 18 {
        i.Break()
    }
}

Range over a sequence of integers from a slice:

for i, n := range goloop.RangeSlice[uint8](250, 255) {
	fmt.Println(i, n)
	if n >= 253 {
		break
	}
}

About

goloop tries to facilitate looping in Go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages