github.com/anacrolix/torrent@v1.61.0/iter.go (about)

     1  package torrent
     2  
     3  import (
     4  	"iter"
     5  
     6  	"golang.org/x/exp/constraints"
     7  )
     8  
     9  // Returns an iterator that yields integers from start (inclusive) to end (exclusive).
    10  func iterRange[T constraints.Integer](start, end T) iter.Seq[T] {
    11  	return func(yield func(T) bool) {
    12  		for i := start; i < end; i++ {
    13  			if !yield(i) {
    14  				return
    15  			}
    16  		}
    17  	}
    18  }