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

     1  package main
     2  
     3  import (
     4  	"github.com/enetx/g"
     5  	"github.com/enetx/g/f"
     6  )
     7  
     8  func main() {
     9  	// Create a slice of strings with empty and non-empty values
    10  	g.SliceOf("", "bbb", "ddd", "", "aaa", "ccc").
    11  		Iter().
    12  		Exclude(f.Zero).
    13  		Cycle().   // Cycle through the elements in the slice
    14  		Take(10).  // Take the first 10 elements from the cycled sequence
    15  		Collect(). // Collect the resulting sequence
    16  		Print()    // Print the collected sequence
    17  
    18  	// Output: Slice[bbb, ddd, aaa, ccc, bbb, ddd, aaa, ccc, bbb, ddd]
    19  }