Documentation
¶
Overview ¶
Package exampleiterator is an example type-safe wrapper of coro.NewIterator.
Example ¶
iter := NewFooIterator(func(yield func(Foo)) error {
for _, foo := range []Foo{"foo", "bar", "baz"} {
yield(foo)
}
return errors.New("done")
})
for iter.Next() {
fmt.Println("yielded:", iter.Yielded)
}
fmt.Println("returned:", iter.Returned)
Output: yielded: foo yielded: bar yielded: baz returned: done
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FooIterator ¶
type FooIterator struct {
// Next blocks until the next Foo is set on Yielded, or until the iterator
// coroutine returns with a (maybe nil) error, which is set on Returned.
Next coro.Resume
Yielded Foo
Returned error
}
A FooIterator holds what's needed to iterate Foos.
func NewFooIterator ¶
func NewFooIterator(f func(yield func(Foo)) error, options ...coro.SetOption) *FooIterator
NewFooIterator wraps coro.NewIterator with a type-safe interface.
Click to show internal directories.
Click to hide internal directories.