dushaoshuai / dushaoshuai.github.io

https://www.shuai.host
0 stars 0 forks source link

package goloop #90

Closed dushaoshuai closed 1 year ago

dushaoshuai commented 1 year ago
for i := range goloop.Repeat(50) { // repeat times may be ommited to specify a 0 times loop
    // Do something with i.
}
// i is of type
// struct {
//     I int
//     Break func() // Break terminates execution of the loop. The current iteration I may be saved in this function to interact with the background goroutine.
// }
for i := range goloop.RepeatWithCancel(100) {
    // Do something with i.I
    fmt.Println(i.I)
    // Call i.Break when some condition is satisfied.
    i.Break()
}
for i := range goloop.Range(5, 10, 2) { // start, end, step, step may be ommited to specify a step 1 or -1
    // i is in range [5, 7, 9]
}
for i := range goloop.Range(goloop.Include(5), goloop.Exclude(11), 2) {
    // i is in range [5, 7, 9]
}
// todo constraints.Ordered
// todo any