github.com/enetx/g@v1.0.80/examples/iter/iter_step.go (about)

     1  package main
     2  
     3  import "github.com/enetx/g"
     4  
     5  func main() {
     6  	// Create a new ordered map with integer keys and string values
     7  	m := g.NewMapOrd[int, string]()
     8  	m.
     9  		Set(0, "aa").
    10  		Set(1, "bb").
    11  		Set(2, "cc").
    12  		Set(3, "ee").
    13  		Set(4, "ff").
    14  		Set(5, "gg").
    15  		Set(6, "aa").
    16  		Iter().
    17  		StepBy(2). // Iterate over the map with a step size of 2
    18  		Collect().
    19  		Print() // MapOrd{0:aa, 2:cc, 4:ff, 6:aa}
    20  }