exampleiterator

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2020 License: MIT Imports: 1 Imported by: 0

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 Foo

type Foo string

Foo is the type that a FooIterator yields.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL