MCPcopy Index your code
hub / github.com/destel/rill / ExampleToSeq2

Function ExampleToSeq2

example123_test.go:50–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48}
49
50func ExampleToSeq2() {
51 // Convert a slice of numbers into a stream
52 numbers := rill.FromSlice([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, nil)
53
54 // Transform each number
55 // Concurrency = 3
56 squares := rill.Map(numbers, 3, func(x int) (int, error) {
57 return square(x), nil
58 })
59
60 // Convert the stream into an iterator and use for-range to print the results
61 for val, err := range rill.ToSeq2(squares) {
62 if err != nil {
63 fmt.Println("Error:", err)
64 break // cleanup is done regardless of early exit
65 }
66 fmt.Printf("%+v\n", val)
67 }
68}

Callers

nothing calls this directly

Calls 4

FromSliceFunction · 0.92
MapFunction · 0.92
ToSeq2Function · 0.92
squareFunction · 0.85

Tested by

no test coverage detected