loop.go raw

   1  package loop
   2  
   3  type to struct {
   4  	Start int
   5  	End   int
   6  }
   7  
   8  func (t *to) Do(fn func(i int)) {
   9  	for ; t.Start != t.End; t.Start++ {
  10  		fn(t.Start)
  11  	}
  12  }
  13  
  14  func To(end int, fn func(i int)) {
  15  	(&to{End: end}).Do(fn)
  16  }
  17