Skip to content

Commit

Permalink
Move ToSeq2 example under 1.23 build
Browse files Browse the repository at this point in the history
  • Loading branch information
amikai committed Aug 1, 2024
1 parent efdefb9 commit abf27ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
31 changes: 31 additions & 0 deletions example123_test.go
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
}
}
}
}
20 changes: 0 additions & 20 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,23 +817,3 @@ func hash(input ...any) int {
fmt.Fprintln(hasher, input...)
return int(hasher.Sum32())
}

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
}
}
}
}

0 comments on commit abf27ba

Please sign in to comment.