Documentation
¶
Overview ¶
Package iterator adapts cursor-style collections into slices, channels, and mapped results.
An Iterator yields values by filling in a pointer — Next(any) bool — which is the shape a database cursor naturally has. Slice, Channel, and Map drain one, calling a caller-supplied constructor once per element; that constructor must return a fresh value every time, because a shared value would leave every result aliasing the same item.
This is the legacy iteration interface, predating range-over-func. New code should prefer iter.Seq and the ranges package; reach for this one only to adapt a type that already implements Iterator.
Index ¶
- func Channel[T any](iterator Iterator, constructor func() T) chan T
- func ChannelWithCancel[T any](iterator Iterator, constructor func() T, cancel <-chan bool) chan T
- func Map[In any, Out any](it Iterator, fn func(In) Out) []Out
- func Slice[T any](iterator Iterator, constructor func() T) []T
- type Iterator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Channel ¶
Channel converts an Iterator into a channel of items. You must include a constructor function that generates fully initialized values of the type you want to return. Deprecated: freeing up this namespace to use for new Go 1.23 range functions
func ChannelWithCancel ¶
ChannelWithCancel converts an Iterator into a channel of items. You must include a constructor function that generates fully initialized values of the type you want to return. Deprecated: freeing up this namespace to use for new Go 1.23 range functions
func Map ¶
Map converts an iterator into a slice of items. Deprecated: freeing up this namespace to use for new Go 1.23 range functions
Types ¶
type Iterator ¶
type Iterator interface {
// Next populates the provided value with the next item, and returns FALSE when the iterator is exhausted
Next(any) bool
// Count returns the total number of items available to this iterator
Count() int
}
Iterator interface allows callers to iterator over a large number of items in an array/slice Deprecated: freeing up this namespace to use for new Go 1.23 range functions