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

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/enetx/g"
     7  )
     8  
     9  func main() {
    10  	// Create a slice of strings with repeated elements
    11  	chunks := g.SliceOf[g.String]("bbb", "ddd", "bbb", "ccc", "aaa", "bbb", "ccc").
    12  		Iter().
    13  		Unique().  // Remove duplicates from the slice
    14  		Chunks(2). // Split the slice into chunks of size 2
    15  		Collect()
    16  
    17  	// Print the resulting chunks
    18  	fmt.Println(chunks)
    19  }