func (iterator Iterator) ToSlice() (list []interface{}, err error) {
	err = iterator.Each(func(item interface{}) {
		list = append(list, item)
	})
	return list, err
}
Convert the iteration directly to a slice.
var list []interface{}
list, err := iterator.ToSlice()
package iter
import "errors"
var FINISHED = errors.New("FINISHED")
type Iterator struct {
	Next func() (interface{}, error)
	Close func()
}
func NewSimple(f func() interface{}) Iterator {
	return Iterator{
		Next: func() (interface{}, error) {
			val := f()
			if val == nil {
				return nil, FINISHED
			} else {
				return f, nil
			}
		},
		Close: func() {},
	}
}
func (iterator Iterator) Map(mapper func(interface{}) interface{}) Iterator {
	return Iterator{
		Next: func() (interface{}, error) {
			item, err := iterator.Next()
			if err != nil {
				return nil, err
			}
			return mapper(item), nil
		},
		Close: func() { iterator.Close() },
	}
}
func (iterator Iterator) Select(selector func(interface{}) bool) Iterator {
	return Iterator{
		Next: func() (interface{}, error) {
			for {
				item, err := iterator.Next()
				if err != nil {
					return nil, err
				}
				if selector(item) {
					return item, nil
				}
			}
		},
		Close: func() { iterator.Close() },
	}
}
func Concat(iterators ...Iterator) Iterator {
	i := 0
	return Iterator{
		Next: func() (interface{}, error) {
			if i >= len(iterators) {
				return nil, FINISHED
			}
			item, err := iterators[i].Next()
			if err == FINISHED {
				i++
				return nil, err
			} else if err != nil {
				i = len(iterators)
				return nil, err
			}
			return item, nil
		},
		Close: func() {
			for ; i < len(iterators); i++ {
				iterators[i].Close()
			}
		},
	}
}
func (iterator Iterator) Each(processor func(interface{})) error {
	defer iterator.Close()
	item, err := iterator.Next()
	for err == nil {
		processor(item)
		item, err = iterator.Next()
	}
	return err
}
func (iterator Iterator) EachWithError(processor func(interface{}) error) error {
	defer iterator.Close()
	item, err := iterator.Next()
	for err == nil {
		err = processor(item)
		if err == nil {
			item, err = iterator.Next()
		}
	}
	return err
}