Documentation
¶
Overview ¶
Package enumerators provides generic iterator utilities such as chunking, mapping, and cleanup behavior for stream-like processing.
Index ¶
- Variables
- func Aggregate[TSource, TAccumulate any](enumerator Enumerator[TSource], seed TAccumulate, ...) (TAccumulate, error)
- func AggregateWithSeed[TSource, TAccumulate any](enumerator Enumerator[TSource], seed TAccumulate, ...) (TAccumulate, error)
- func All[T any](enumerator Enumerator[T], predicate func(T) bool) (bool, error)
- func Any[T any](enumerator Enumerator[T], predicate func(T) bool) (bool, error)
- func Cleanup[T any](enumerator Enumerator[T], cleanup func()) *cleanupEnumerator[T]
- func Collect[T any](enumerator Enumerator[Enumerator[T]]) ([][]T, error)
- func Consume[T any](e Enumerator[T]) error
- func Contains[T comparable](enumerator Enumerator[T], value T) (bool, error)
- func Count[T any](enumerator Enumerator[T]) (int, error)
- func ElementAt[T any](enumerator Enumerator[T], index int) (T, error)
- func First[T any](enumerator Enumerator[T]) (T, error)
- func ForEach[T any](enumerator Enumerator[T], do func(T) error) error
- func Last[T any](enumerator Enumerator[T]) (T, error)
- func Max[T constraints.Ordered](enumerator Enumerator[T]) (T, error)
- func Min[T constraints.Ordered](enumerator Enumerator[T]) (T, error)
- func Partition[T any](enumerator Enumerator[T], predicate func(T) bool) (Enumerator[T], Enumerator[T])
- func SequenceEqual[T comparable](first, second Enumerator[T]) (bool, error)
- func Single[T any](enumerator Enumerator[T]) (T, error)
- func Sum[T any, TSum constraints.Ordered](enumerator Enumerator[T], selector func(item T) (TSum, error)) (TSum, error)
- func ToMap[T any, TKey comparable, TValue any](enumerator Enumerator[T], keyFn func(T) TKey, valFn func(T) TValue) (map[TKey]TValue, error)
- func ToMapWithKey[TKey comparable, TValue any](enumerator Enumerator[TValue], keyFn func(TValue) TKey) (map[TKey]TValue, error)
- func ToSlice[T any](enumerator Enumerator[T]) ([]T, error)
- type ChannelEnumerator
- func (e *ChannelEnumerator[T]) Complete()
- func (e *ChannelEnumerator[T]) Current() (T, error)
- func (e *ChannelEnumerator[T]) Dispose()
- func (e *ChannelEnumerator[T]) Err() error
- func (e *ChannelEnumerator[T]) Error(err error)
- func (e *ChannelEnumerator[T]) MoveNext() bool
- func (e *ChannelEnumerator[T]) Publish(msg T) bool
- type Disposable
- type Enumerator
- func Chain[T any](enumerators ...Enumerator[T]) Enumerator[T]
- func Chunk[T any, TSize constraints.Ordered](in Enumerator[T], target TSize, compute func(item T) (TSize, error)) Enumerator[Enumerator[T]]
- func ChunkByCount[T any](in Enumerator[T], count int) Enumerator[Enumerator[T]]
- func ChunkByKey[V any, K comparable](in Enumerator[V], keyFunc func(V) K) Enumerator[KeyedChunk[K, V]]
- func ChunkWhen[V any, K comparable](in Enumerator[V], split func(item V) (K, bool, error)) Enumerator[KeyedChunk[K, V]]
- func DefaultIfEmpty[T any](enumerator Enumerator[T], defaultValue T) Enumerator[T]
- func Distinct[T comparable](enumerator Enumerator[T]) Enumerator[T]
- func Empty[T any]() Enumerator[T]
- func Error[T any](err error) Enumerator[T]
- func Except[T comparable](first, second Enumerator[T]) Enumerator[T]
- func Filter[T any](parent Enumerator[T], filter func(T) bool) Enumerator[T]
- func FilterMap[TIn any, TOut any](enumerator Enumerator[TIn], apply func(TIn) (TOut, bool, error)) Enumerator[TOut]
- func FilterWithContext[T any](ctx context.Context, enumerator Enumerator[T], ...) Enumerator[T]
- func FlatMap[T any, U any](parent Enumerator[T], mapper func(T) Enumerator[U]) Enumerator[U]
- func Generate[T any](next func() (T, bool, error)) Enumerator[T]
- func GenerateAndDispose[T any](next func() (T, bool, error), dispose func()) Enumerator[T]
- func GenerateFromMap[K comparable, V any](m map[K]V) Enumerator[*KeyValuePair[K, V]]
- func Group[T any, G comparable](in Enumerator[T], compute func(item T) (G, error)) Enumerator[*Grouping[T, G]]
- func Interleave[T any, TOrdered constraints.Ordered](enumerators []Enumerator[T], key func(T) TOrdered) Enumerator[T]
- func Intersect[T comparable](first, second Enumerator[T]) Enumerator[T]
- func Map[T any, U any](enumerator Enumerator[T], mapper func(T) (U, error)) Enumerator[U]
- func MapWithContext[T any, U any](ctx context.Context, enumerator Enumerator[T], ...) Enumerator[U]
- func PageItemEnumerator[T any](fetchPage func() ([]T, bool, error)) Enumerator[T]
- func Range[T any](seed int, count int, factory func(i int) T) Enumerator[T]
- func Reverse[T any](enumerator Enumerator[T]) Enumerator[T]
- func Sample[T any](enumerator Enumerator[T], n int) Enumerator[T]
- func Skip[T any](enumerator Enumerator[T], n int) Enumerator[T]
- func SkipIf[T any](enumerator Enumerator[T], condition func(T) bool) Enumerator[T]
- func Slice[T any](slice []T) Enumerator[T]
- func Sort[T any](enumerator Enumerator[T], less func(a, b T) bool) Enumerator[T]
- func Take[T any](enumerator Enumerator[T], take int) Enumerator[T]
- func TakeWhile[T any](enumerator Enumerator[T], condition func(T) bool) Enumerator[T]
- func Union[T comparable](first, second Enumerator[T]) Enumerator[T]
- func Zip[T, U any](first Enumerator[T], second Enumerator[U]) Enumerator[Pair[T, U]]
- type Generator
- type GroupEnumerator
- type Grouping
- type GroupingSlice
- type KeyValuePair
- type KeyedChunk
- type Pair
- type PeekableEnumerator
- type SliceEnumerator
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptySequence is returned when an operation expects at least one element but the sequence is empty. ErrEmptySequence = errors.New("sequence contains no elements") // ErrDisposed is returned when attempting to access a disposed enumerator. ErrDisposed = errors.New("enumerator disposed") )
Functions ¶
func Aggregate ¶
func Aggregate[TSource, TAccumulate any](enumerator Enumerator[TSource], seed TAccumulate, accumulator func(TAccumulate, TSource) (TAccumulate, error)) (TAccumulate, error)
Aggregate applies an accumulator function over the enumerator. Returns the final accumulator value and any error encountered. If the enumerator is empty, returns the zero value of TAccumulate and an error.
func AggregateWithSeed ¶
func AggregateWithSeed[TSource, TAccumulate any](enumerator Enumerator[TSource], seed TAccumulate, accumulator func(TAccumulate, TSource) TAccumulate) (TAccumulate, error)
AggregateWithSeed applies an accumulator function over the enumerator starting with a seed value. Unlike Aggregate, this always succeeds even for empty enumerators.
func All ¶
func All[T any](enumerator Enumerator[T], predicate func(T) bool) (bool, error)
All returns true if all elements satisfy the predicate. If the enumerator is empty, returns true. The enumerator is disposed after checking.
func Any ¶
func Any[T any](enumerator Enumerator[T], predicate func(T) bool) (bool, error)
Any returns true if at least one element satisfies the predicate. If the enumerator is empty, returns false. The enumerator is disposed after checking.
func Cleanup ¶
func Cleanup[T any](enumerator Enumerator[T], cleanup func()) *cleanupEnumerator[T]
Cleanup wraps an enumerator with a cleanup function that runs on Dispose.
func Collect ¶
func Collect[T any](enumerator Enumerator[Enumerator[T]]) ([][]T, error)
Collect gathers all chunks from a chunked enumerator into a slice of slices. The outer enumerator is automatically disposed after collection completes.
func Consume ¶
func Consume[T any](e Enumerator[T]) error
Consume advances the enumerator to completion and disposes it. It returns any error encountered during iteration.
func Contains ¶
func Contains[T comparable](enumerator Enumerator[T], value T) (bool, error)
Contains returns true if the enumerator contains the specified value. The enumerator is disposed after checking.
func Count ¶
func Count[T any](enumerator Enumerator[T]) (int, error)
Count returns the number of elements in the enumerator. The enumerator is disposed after counting.
func ElementAt ¶
func ElementAt[T any](enumerator Enumerator[T], index int) (T, error)
ElementAt returns the element at the specified zero-based index. If index is out of bounds, returns zero value and error. The enumerator is disposed after finding the element.
func First ¶
func First[T any](enumerator Enumerator[T]) (T, error)
First returns the first element of the enumerator. If the enumerator is empty, returns ErrEmptySequence. The enumerator is disposed after getting the first element.
func ForEach ¶
func ForEach[T any](enumerator Enumerator[T], do func(T) error) error
ForEach iterates over all elements in the enumerator, calling the provided action function for each element. The enumerator is automatically disposed after iteration completes or when an error occurs. Returns the first error encountered during iteration or from the action function.
func Last ¶
func Last[T any](enumerator Enumerator[T]) (T, error)
Last returns the last element of the enumerator. If the enumerator is empty, returns ErrEmptySequence. The enumerator is disposed after consuming all elements.
func Max ¶
func Max[T constraints.Ordered](enumerator Enumerator[T]) (T, error)
Max returns the maximum element in the enumerator. If the enumerator is empty, returns the zero value. The enumerator is disposed after finding the maximum.
func Min ¶
func Min[T constraints.Ordered](enumerator Enumerator[T]) (T, error)
Min returns the minimum element in the enumerator. If the enumerator is empty, returns the zero value. The enumerator is disposed after finding the minimum.
func Partition ¶
func Partition[T any](enumerator Enumerator[T], predicate func(T) bool) (Enumerator[T], Enumerator[T])
Partition splits the enumerator into two based on a predicate. Returns two enumerators: one for elements where predicate is true, one for false. The original enumerator is consumed eagerly.
func SequenceEqual ¶
func SequenceEqual[T comparable](first, second Enumerator[T]) (bool, error)
SequenceEqual determines whether two enumerators are equal by comparing their elements. Both enumerators are consumed during the comparison. Returns true if both sequences contain the same elements in the same order.
func Single ¶
func Single[T any](enumerator Enumerator[T]) (T, error)
Single returns the single element if the enumerator has exactly one element. If empty, returns ErrEmptySequence. If more than one, returns the first and error. The enumerator is disposed after checking.
func Sum ¶
func Sum[T any, TSum constraints.Ordered](enumerator Enumerator[T], selector func(item T) (TSum, error)) (TSum, error)
Sum consumes an enumerator and returns the sum of all elements after applying a selector function. The enumerator is automatically disposed after computation. Returns an error if enumeration fails or if the selector function returns an error.
func ToMap ¶
func ToMap[T any, TKey comparable, TValue any](enumerator Enumerator[T], keyFn func(T) TKey, valFn func(T) TValue) (map[TKey]TValue, error)
ToMap iterates over the provided enumerator and builds a map by applying the keyFn and valFn to each item. The resulting map uses the key from keyFn(item) and the value from valFn(item). If the enumerator yields an error during iteration, the function returns immediately with that error.
The enumerator is disposed automatically at the end of processing.
Returns an error if iteration fails. If the enumerator is nil, returns nil, nil.
func ToMapWithKey ¶
func ToMapWithKey[TKey comparable, TValue any](enumerator Enumerator[TValue], keyFn func(TValue) TKey) (map[TKey]TValue, error)
ToMapWithKey iterates over the provided enumerator and builds a map using each item as the value. The key for each entry is computed by applying keyFn(item).
The enumerator is disposed automatically at the end of processing.
Returns an error if iteration fails. If the enumerator is nil, returns nil, nil.
func ToSlice ¶
func ToSlice[T any](enumerator Enumerator[T]) ([]T, error)
ToSlice converts an enumerator to a slice by consuming all its elements. The enumerator is automatically disposed after consumption.
Types ¶
type ChannelEnumerator ¶
type ChannelEnumerator[T any] struct { // contains filtered or unexported fields }
ChannelEnumerator provides enumeration over channels with context support. It supports publishing values, error handling, and graceful termination.
func Channel ¶
func Channel[T any](ctx context.Context, size int) *ChannelEnumerator[T]
Channel creates a new channel-based enumerator with the specified buffer size. The enumerator respects the provided context for cancellation.
func (*ChannelEnumerator[T]) Complete ¶
func (e *ChannelEnumerator[T]) Complete()
Complete signals that no more values will be published.
func (*ChannelEnumerator[T]) Current ¶
func (e *ChannelEnumerator[T]) Current() (T, error)
Current returns the current value and any error encountered.
func (*ChannelEnumerator[T]) Dispose ¶
func (e *ChannelEnumerator[T]) Dispose()
Dispose cleans up resources and signals termination.
func (*ChannelEnumerator[T]) Err ¶
func (e *ChannelEnumerator[T]) Err() error
Err returns any error encountered during enumeration.
func (*ChannelEnumerator[T]) Error ¶
func (e *ChannelEnumerator[T]) Error(err error)
Error signals an error to the enumerator.
func (*ChannelEnumerator[T]) MoveNext ¶
func (e *ChannelEnumerator[T]) MoveNext() bool
MoveNext advances the enumerator to the next value in the range. Returns true if more values are available, false otherwise.
func (*ChannelEnumerator[T]) Publish ¶
func (e *ChannelEnumerator[T]) Publish(msg T) bool
Publish sends a value to the enumerator for consumption.
type Disposable ¶
type Disposable interface {
// Dispose releases any resources held by this object.
// It should be safe to call Dispose multiple times.
Dispose()
}
Disposable represents an object that holds resources that need to be explicitly released. Implementers should ensure that Dispose can be called multiple times safely.
type Enumerator ¶
type Enumerator[T any] interface { Disposable MoveNext() bool Current() (T, error) Err() error }
Enumerator represents a generic iterator over a sequence of values of type T. It should be disposed when no longer needed.
func Chain ¶
func Chain[T any](enumerators ...Enumerator[T]) Enumerator[T]
Chain creates an enumerator that sequentially chains multiple enumerators together. Elements from each enumerator are yielded in order until that enumerator is exhausted, then the next enumerator in the chain begins yielding elements.
func Chunk ¶
func Chunk[T any, TSize constraints.Ordered]( in Enumerator[T], target TSize, compute func(item T) (TSize, error), ) Enumerator[Enumerator[T]]
Chunk creates an enumerator that groups elements into chunks based on a target size. The compute function determines the size contribution of each element. Each chunk is yielded as a separate enumerator when the cumulative size reaches or exceeds the target.
func ChunkByCount ¶
func ChunkByCount[T any](in Enumerator[T], count int) Enumerator[Enumerator[T]]
ChunkByCount creates an enumerator that groups elements into chunks of a specified count. Each chunk contains at most 'count' elements, with the final chunk potentially containing fewer.
func ChunkByKey ¶
func ChunkByKey[V any, K comparable]( in Enumerator[V], keyFunc func(V) K, ) Enumerator[KeyedChunk[K, V]]
ChunkByKey splits an input stream into chunks based on a computed key. Each chunk yields items sharing the same key, wrapped in a KeyedChunk.
func ChunkWhen ¶
func ChunkWhen[V any, K comparable]( in Enumerator[V], split func(item V) (K, bool, error), ) Enumerator[KeyedChunk[K, V]]
ChunkWhen groups items into chunks based on a split function. It emits KeyedChunk[K, V] where each chunk has a key and a stream of values.
func DefaultIfEmpty ¶
func DefaultIfEmpty[T any](enumerator Enumerator[T], defaultValue T) Enumerator[T]
DefaultIfEmpty returns the elements of the enumerator, or a singleton sequence containing the default value if the enumerator is empty.
func Distinct ¶
func Distinct[T comparable](enumerator Enumerator[T]) Enumerator[T]
Distinct creates an enumerator that yields unique elements. Elements are compared using ==, so T must be comparable.
func Error ¶
func Error[T any](err error) Enumerator[T]
Error creates an enumerator that immediately returns the specified error. This is useful for creating error states in enumerator chains.
func Except ¶
func Except[T comparable](first, second Enumerator[T]) Enumerator[T]
Except returns an enumerator with elements from first enumerator not in second. Preserves order from first enumerator.
func Filter ¶
func Filter[T any](parent Enumerator[T], filter func(T) bool) Enumerator[T]
Filter creates an enumerator that only yields elements satisfying the predicate function. The filter function receives an element of type T and returns true if the element should be included.
func FilterMap ¶
func FilterMap[TIn any, TOut any](enumerator Enumerator[TIn], apply func(TIn) (TOut, bool, error)) Enumerator[TOut]
FilterMap creates an enumerator that applies both transformation and filtering in a single pass. The apply function receives an element and returns (transformedValue, shouldInclude, error). Only elements where shouldInclude is true are yielded after transformation.
func FilterWithContext ¶
func FilterWithContext[T any](ctx context.Context, enumerator Enumerator[T], predicate func(context.Context, T) bool) Enumerator[T]
FilterWithContext filters elements based on a predicate with context support. The predicate function receives context for cancellation. If context is cancelled, enumeration stops and returns the cancellation error.
func FlatMap ¶
func FlatMap[T any, U any](parent Enumerator[T], mapper func(T) Enumerator[U]) Enumerator[U]
FlatMap creates an enumerator that applies a function to each element and flattens the results. The mapper function receives an element of type T and returns an enumerator of type U. All elements from each returned enumerator are yielded in sequence.
func Generate ¶
func Generate[T any](next func() (T, bool, error)) Enumerator[T]
Generate creates a new enumerator using a generator function. The next function should return (value, hasNext, error) where hasNext indicates if more values are available. If error is not nil, hasNext should be false; otherwise, behavior is undefined. If next is nil, Generate panics.
func GenerateAndDispose ¶
func GenerateAndDispose[T any](next func() (T, bool, error), dispose func()) Enumerator[T]
GenerateAndDispose creates a new enumerator with both generator and disposal functions. The dispose function is called when the enumerator is disposed to clean up resources.
func GenerateFromMap ¶
func GenerateFromMap[K comparable, V any](m map[K]V) Enumerator[*KeyValuePair[K, V]]
GenerateFromMap creates an enumerator that yields key-value pairs from a map. The order of enumeration is not guaranteed to be consistent across calls.
func Group ¶
func Group[T any, G comparable]( in Enumerator[T], compute func(item T) (G, error), ) Enumerator[*Grouping[T, G]]
func Interleave ¶
func Interleave[T any, TOrdered constraints.Ordered]( enumerators []Enumerator[T], key func(T) TOrdered, ) Enumerator[T]
Interleave creates a new interleave enumerator that merges multiple enumerators based on the ordering provided by the key function.
func Intersect ¶
func Intersect[T comparable](first, second Enumerator[T]) Enumerator[T]
Intersect returns an enumerator with elements present in both enumerators. Preserves order from first enumerator.
func Map ¶
func Map[T any, U any](enumerator Enumerator[T], mapper func(T) (U, error)) Enumerator[U]
Map creates an enumerator that applies a transformation function to each element. The mapper function receives an element of type T and returns a transformed element of type U. If the mapper function returns an error, enumeration stops and the error is propagated.
func MapWithContext ¶
func MapWithContext[T any, U any](ctx context.Context, enumerator Enumerator[T], mapper func(context.Context, T) (U, error)) Enumerator[U]
MapWithContext applies a transformation function to each element with context support. The mapper function receives context for cancellation and the element to transform. If context is cancelled, enumeration stops and returns the cancellation error.
func PageItemEnumerator ¶
func PageItemEnumerator[T any](fetchPage func() ([]T, bool, error)) Enumerator[T]
PageItemEnumerator creates an enumerator that handles paginated data by calling a fetch function. The fetchPage function should return (items, hasMore, error) where hasMore indicates if additional pages exist.
func Range ¶
func Range[T any](seed int, count int, factory func(i int) T) Enumerator[T]
Range creates an enumerator that generates a sequence of values using a factory function. It starts at 'seed' and generates 'count' values by calling factory(i) for i from seed to seed+count-1.
func Reverse ¶
func Reverse[T any](enumerator Enumerator[T]) Enumerator[T]
Reverse reverses the order of elements in the enumerator. The enumerator is consumed eagerly, then returned as a new enumerator in reverse order.
func Sample ¶
func Sample[T any](enumerator Enumerator[T], n int) Enumerator[T]
Sample returns a random sample of n elements from the enumerator. If n >= length, returns all elements in random order. The enumerator is consumed eagerly.
func Skip ¶
func Skip[T any](enumerator Enumerator[T], n int) Enumerator[T]
Skip creates an enumerator that skips the first N elements. If N is negative or zero, returns the original enumerator without wrapping.
func SkipIf ¶
func SkipIf[T any](enumerator Enumerator[T], condition func(T) bool) Enumerator[T]
SkipIf creates an enumerator that skips elements satisfying the specified condition. Elements are skipped when condition(element) returns true.
func Slice ¶
func Slice[T any](slice []T) Enumerator[T]
Slice creates a new enumerator that iterates over the provided slice.
func Sort ¶
func Sort[T any](enumerator Enumerator[T], less func(a, b T) bool) Enumerator[T]
Sort sorts the elements of the enumerator using the provided less function. The enumerator is consumed and sorted eagerly, then returned as a new enumerator. The less function should return true if a < b.
func Take ¶
func Take[T any](enumerator Enumerator[T], take int) Enumerator[T]
Take creates an enumerator that yields at most the specified number of elements. If take is negative or zero, the enumerator will yield no elements.
func TakeWhile ¶
func TakeWhile[T any](enumerator Enumerator[T], condition func(T) bool) Enumerator[T]
TakeWhile creates an enumerator that yields elements while the specified condition is satisfied. Enumeration stops as soon as any element fails the condition.
func Union ¶
func Union[T comparable](first, second Enumerator[T]) Enumerator[T]
Union returns an enumerator with unique elements from both enumerators. Preserves order from first enumerator, then adds from second.
func Zip ¶
func Zip[T, U any](first Enumerator[T], second Enumerator[U]) Enumerator[Pair[T, U]]
Zip combines two enumerators into one, yielding pairs of elements. Stops when either enumerator is exhausted.
type Generator ¶
type Generator[T any] struct { Enumerator[T] // contains filtered or unexported fields }
Generator generates values continuously.
type GroupEnumerator ¶
type GroupEnumerator[T any, G comparable] struct { // contains filtered or unexported fields }
func (*GroupEnumerator[T, G]) Current ¶
func (e *GroupEnumerator[T, G]) Current() (*Grouping[T, G], error)
func (*GroupEnumerator[T, G]) Dispose ¶
func (e *GroupEnumerator[T, G]) Dispose()
func (*GroupEnumerator[T, G]) Err ¶
func (e *GroupEnumerator[T, G]) Err() error
func (*GroupEnumerator[T, G]) MoveNext ¶
func (e *GroupEnumerator[T, G]) MoveNext() bool
type Grouping ¶
type Grouping[T any, G comparable] struct { Enumerator *innerGroupEnumerator[T, G] Key G }
Grouping represents a group of elements with a common key.
type GroupingSlice ¶
type GroupingSlice[T any, G comparable] struct { Items []T Group G }
GroupingSlice represents a slice of elements grouped by a key.
func CollectGroupingSlices ¶
func CollectGroupingSlices[T any, G comparable](enumerator Enumerator[*Grouping[T, G]]) (groupSlices []*GroupingSlice[T, G], err error)
CollectGroupingSlices gathers all chunks into a slice of slices
type KeyValuePair ¶
type KeyValuePair[K comparable, V any] struct { Key K Value V }
KeyValuePair represents a key-value pair for map enumeration.
type KeyedChunk ¶
type KeyedChunk[K comparable, V any] struct { Key K Chunk Enumerator[V] }
KeyedChunk represents a chunk of items that share the same key.
type Pair ¶
type Pair[T, U any] struct { First T Second U }
Pair represents a pair of values from Zip operation.
type PeekableEnumerator ¶
type PeekableEnumerator[T any] struct { // contains filtered or unexported fields }
PeekableEnumerator wraps an Enumerator and adds peek functionality
func Peekable ¶
func Peekable[T any](inner Enumerator[T]) *PeekableEnumerator[T]
Peekable creates a peekable enumerator that allows looking ahead at the next element without advancing the enumerator position.
func (*PeekableEnumerator[T]) Current ¶
func (p *PeekableEnumerator[T]) Current() (T, error)
Current returns the current element
func (*PeekableEnumerator[T]) Dispose ¶
func (p *PeekableEnumerator[T]) Dispose()
Dispose releases resources
func (*PeekableEnumerator[T]) Err ¶
func (p *PeekableEnumerator[T]) Err() error
Err returns the last error from the underlying enumerator
func (*PeekableEnumerator[T]) HasNext ¶
func (p *PeekableEnumerator[T]) HasNext() bool
HasNext checks if there is a next element available without advancing the enumerator
func (*PeekableEnumerator[T]) MoveNext ¶
func (p *PeekableEnumerator[T]) MoveNext() bool
MoveNext advances to the next element
func (*PeekableEnumerator[T]) Peek ¶
func (p *PeekableEnumerator[T]) Peek() (T, bool, error)
Peek allows looking at the next element without advancing the enumerator
type SliceEnumerator ¶
type SliceEnumerator[T any] struct { // contains filtered or unexported fields }
SliceEnumerator provides enumeration over a Go slice.
func (*SliceEnumerator[T]) Current ¶
func (e *SliceEnumerator[T]) Current() (T, error)
Current returns the current element and any error encountered.
func (*SliceEnumerator[T]) Dispose ¶
func (enumerator *SliceEnumerator[T]) Dispose()
Dispose cleans up resources. For SliceEnumerator, this is a no-op.
func (*SliceEnumerator[T]) Err ¶
func (e *SliceEnumerator[T]) Err() error
Err returns any error encountered during enumeration.
func (*SliceEnumerator[T]) MoveNext ¶
func (e *SliceEnumerator[T]) MoveNext() bool
MoveNext advances the enumerator to the next element in the slice. Returns true if more elements are available, false otherwise.
Source Files
¶
- aggregate.go
- any_all.go
- chain.go
- channel.go
- chunk.go
- chunk_by_key.go
- chunk_when.go
- contains.go
- context.go
- count.go
- default_if_empty.go
- disposable.go
- distinct.go
- element_single.go
- enumerator.go
- error.go
- filter.go
- filter_map.go
- first_last.go
- flat_map.go
- foreach.go
- generator.go
- group.go
- interleave.go
- map.go
- min_max.go
- page_item.go
- partition.go
- peekable.go
- range.go
- sample.go
- sequence_equal.go
- sets.go
- skip.go
- skip_if.go
- slice.go
- sort_reverse.go
- sum.go
- take.go
- take_while.go
- zip.go