Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrStopGenerator = errors.New("stop generator")
ErrStopGenerator signals to the generator that it must stop.
Functions ¶
This section is empty.
Types ¶
type G ¶
type G[T any] struct { // contains filtered or unexported fields }
G represents a Generator producing items which can be received through an iterator.
func (*G[T]) Send ¶
func (g *G[T]) Send(v T)
Send is called from a running GeneratorFn and sends the given Value to the [Iterator] caller.
It panics when the Generator has to stop.
type GIterator ¶
type GIterator[T any] struct { *chanit.ChannelIterator[T] // contains filtered or unexported fields }
GIterator represents the receiver facing [Iterator] end of a Generator.
func Generator ¶
func Generator[T any](fn GeneratorFn[T]) *GIterator[T]
Generator starts the GeneratorFn function as a new GIterator.
The Generator will be stopped automatically when the returned GIterator is garbage collected.
The Generator API is experimental and probably will change.
func GeneratorNoGC ¶
func GeneratorNoGC[T any](fn GeneratorFn[T]) *GIterator[T]
GeneratorNoGC starts the GeneratorFn function as a new GIterator.
Please consider using Generator for simplicity reasons unless the Garbage Collector is a concern.
The Generator will not be stopped automatically and itkit.GIterator.Stop must be called on the returned to stop the generator manually.
The Generator API is experimental and probably will change.
func (*GIterator[T]) Iter ¶
Iter returns the underlying [Iterator] of the GIterator yielding items produced by the generator until the generator function is gone.
type GeneratorFn ¶
GeneratorFn is a function that generates items and sends them to the Iterator through G.Send.