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

     1  package main
     2  
     3  import "github.com/enetx/g"
     4  
     5  func main() {
     6  	// Create a slice of integers with repeated elements
     7  	g.SliceOf(1, 1, 1, 3, 4, 4, 8, 8, 9, 9).
     8  		Iter().
     9  		Dedup().   // Remove duplicate elements
    10  		Collect(). // Collect the resulting slice
    11  		Print()    // Print the collected slice: Slice[1, 3, 4, 8, 9]
    12  
    13  	g.SliceOf([]int{1, 2, 3}, []int{1, 2, 3}, []int{1, 2}).
    14  		Iter().
    15  		Dedup().
    16  		Collect().
    17  		Print() // Slice[[1 2 3], [1 2]]
    18  }