-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move ToSeq2 example under 1.23 build
- Loading branch information
Showing
2 changed files
with
31 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//go:build go1.23 | ||
// +build go1.23 | ||
|
||
package rill_test | ||
|
||
import ( | ||
"fmt" | ||
"iter" | ||
|
||
"github.com/destel/rill" | ||
) | ||
|
||
func Example_ToSeq2() { | ||
nums := rill.FromSeq2(genPositive(40)) | ||
doubleNums := rill.Map(nums, 4, func(x int) (int, error) { | ||
return x * x, nil | ||
}) | ||
for val, err := range rill.ToSeq2(doubleNums) { | ||
fmt.Println(val, err) | ||
} | ||
} | ||
|
||
func genPositive(to int) iter.Seq2[int, error] { | ||
return func(yield func(i int, err error) bool) { | ||
for i := 1; i <= to; i++ { | ||
if !yield(i, nil) { | ||
return | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters