github.com/enetx/g@v1.0.80/examples/iter/iter_windows.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 integers
    11  	windows := g.SliceOf(1, 2, 3, 4).
    12  		Iter().
    13  		Windows(2). // Create windows of size 2
    14  		Collect()   // Collect the resulting windows
    15  
    16  	// Print the collected windows
    17  	fmt.Println(windows) // [Slice[1, 2] Slice[2, 3] Slice[3, 4]]
    18  
    19  	// Convert to iterator
    20  	g.SliceOf(windows...).Iter()
    21  }