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

     1  package main
     2  
     3  import "github.com/enetx/g"
     4  
     5  func main() {
     6  	// Create a slice of strings
     7  	ps := g.SliceOf[g.String]("bbb", "ddd", "xxx", "aaa", "ccc").
     8  		Iter().
     9  		Enumerate(). // Enumerate the elements, creating pairs of index and value
    10  		Collect()    // Collect the resulting pairs
    11  
    12  	// Print the ordered map
    13  	ps.Print() // MapOrd{0:bbb, 1:ddd, 2:xxx, 3:aaa, 4:ccc}
    14  }