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

     1  package main
     2  
     3  import (
     4  	"github.com/enetx/g"
     5  )
     6  
     7  func main() {
     8  	// Create two slices of strings, p1 and p2
     9  	p1 := g.SliceOf[g.String]("bbb", "ddd")
    10  	p2 := g.SliceOf[g.String]("xxx", "aaa")
    11  
    12  	// Chain the iterators of p1 and p2 and collect the results into a new slice pp
    13  	pp := p1.
    14  		Iter().
    15  		Chain(p2.Iter()).
    16  		Collect()
    17  
    18  	// Iterate over the resulting slice pp and print each element
    19  	for _, v := range pp {
    20  		v.Print()
    21  	}
    22  }