iter

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package iter provides implementations of slice based itarators

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[TS ~[]T, T any](elements TS) *slice.Iter[T]

New is the main slice-based iterator constructor

Types

type ConvFitIter

type ConvFitIter[From, To any] struct {
	// contains filtered or unexported fields
}

ConvFitIter is the array based Iterator thath provides converting of elements by a Converter with addition filtering of the elements by a Predicate.

func FiltAndConv

func FiltAndConv[FS ~[]From, From, To any](elements FS, filter func(From) (bool, error), converter func(From) (To, error)) *ConvFitIter[From, To]

FiltAndConv additionally filters 'From' elements.

func (*ConvFitIter[From, To]) Cap

func (i *ConvFitIter[From, To]) Cap() int

Cap returns the iterator capacity

func (*ConvFitIter[From, To]) For

func (i *ConvFitIter[From, To]) For(walker func(element To) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*ConvFitIter[From, To]) Next

func (i *ConvFitIter[From, To]) Next() (t To, ok bool, err error)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

type ConvIter

type ConvIter[From, To any] struct {
	// contains filtered or unexported fields
}

ConvIter is the array based Iterator thath provides converting of elements by a ConvIter.

func Conv

func Conv[FS ~[]From, From, To any](elements FS, converter func(From) (To, error)) *ConvIter[From, To]

Conv instantiates an iterator that converts elements with a converter and returns them

func (*ConvIter[From, To]) Cap

func (i *ConvIter[From, To]) Cap() int

Cap returns the iterator capacity

func (*ConvIter[From, To]) For

func (i *ConvIter[From, To]) For(walker func(element To) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*ConvIter[From, To]) Next

func (i *ConvIter[From, To]) Next() (t To, ok bool, err error)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

type ConvertFitIter

type ConvertFitIter[From, To any] struct {
	// contains filtered or unexported fields
}

ConvertFitIter is the array based Iterator thath provides converting of elements by a Converter with addition filtering of the elements by a Predicate.

func FilterAndConvert

func FilterAndConvert[FS ~[]From, From, To any](elements FS, filter func(From) bool, converter func(From) To) *ConvertFitIter[From, To]

FilterAndConvert returns a stream that filters source elements and converts them

func (*ConvertFitIter[From, To]) Cap

func (i *ConvertFitIter[From, To]) Cap() int

Cap returns the iterator capacity

func (*ConvertFitIter[From, To]) For

func (i *ConvertFitIter[From, To]) For(walker func(element To) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*ConvertFitIter[From, To]) ForEach

func (i *ConvertFitIter[From, To]) ForEach(walker func(element To))

ForEach FlatIter all elements retrieved by the iterator

func (*ConvertFitIter[From, To]) Next

func (i *ConvertFitIter[From, To]) Next() (t To, ok bool)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

type ConvertIter

type ConvertIter[From, To any] struct {
	// contains filtered or unexported fields
}

ConvertIter is the array based Iterator thath provides converting of elements by a ConvertIter.

func Convert

func Convert[FS ~[]From, From, To any](elements FS, converter func(From) To) *ConvertIter[From, To]

Convert instantiates an iterator that converts elements with a converter and returns them

func (*ConvertIter[From, To]) Cap

func (i *ConvertIter[From, To]) Cap() int

Cap returns the iterator capacity

func (*ConvertIter[From, To]) For

func (i *ConvertIter[From, To]) For(walker func(element To) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*ConvertIter[From, To]) ForEach

func (i *ConvertIter[From, To]) ForEach(walker func(element To))

ForEach FlatIter all elements retrieved by the iterator

func (*ConvertIter[From, To]) Next

func (i *ConvertIter[From, To]) Next() (To, bool)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

type FiltIter

type FiltIter[T any] struct {
	// contains filtered or unexported fields
}

FiltIter is the array based Iterator implementation that provides filtering of elements by a Predicate.

func Filt

func Filt[TS ~[]T, T any](elements TS, filter func(T) (bool, error)) *FiltIter[T]

Filt instantiates an iterator that checks elements by the 'filter' function and returns successful ones

func (*FiltIter[T]) Cap

func (f *FiltIter[T]) Cap() int

Cap returns the iterator capacity

func (*FiltIter[T]) For

func (f *FiltIter[T]) For(walker func(element T) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*FiltIter[T]) Next

func (f *FiltIter[T]) Next() (T, bool, error)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

type FilterIter

type FilterIter[T any] struct {
	// contains filtered or unexported fields
}

FilterIter is the array based Iterator implementation that provides filtering of elements by a Predicate.

func Filter

func Filter[TS ~[]T, T any](elements TS, filter func(T) bool) *FilterIter[T]

Filter instantiates an iterator that checks elements by the 'filter' function and returns successful ones

func NotNil

func NotNil[T any, TRS ~[]*T](elements TRS) *FilterIter[*T]

NotNil instantiates an iterator that filters nullable elements

func (*FilterIter[T]) Cap

func (f *FilterIter[T]) Cap() int

Cap returns the iterator capacity

func (*FilterIter[T]) For

func (f *FilterIter[T]) For(walker func(element T) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*FilterIter[T]) ForEach

func (f *FilterIter[T]) ForEach(walker func(element T))

ForEach FlatIter all elements retrieved by the iterator

func (*FilterIter[T]) Next

func (f *FilterIter[T]) Next() (T, bool)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

type FlatFiltIter

type FlatFiltIter[From, To any] struct {
	// contains filtered or unexported fields
}

FlatFiltIter is the array based Iterator impelementation that converts an element to a slice with addition filtering of the element by a Predicate and iterates over the slice.

func FiltAndFlat

func FiltAndFlat[FS ~[]From, From, To any](elements FS, filter func(From) (bool, error), flatt func(From) ([]To, error)) *FlatFiltIter[From, To]

FiltAndFlat instantiates an iterator that filters elements by the 'filter' function, flattens elements and returns them.

func (*FlatFiltIter[From, To]) Cap

func (f *FlatFiltIter[From, To]) Cap() int

Cap returns the iterator capacity

func (*FlatFiltIter[From, To]) For

func (f *FlatFiltIter[From, To]) For(walker func(element To) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*FlatFiltIter[From, To]) Next

func (f *FlatFiltIter[From, To]) Next() (t To, ok bool, err error)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

type FlatIter

type FlatIter[From, To any] struct {
	// contains filtered or unexported fields
}

FlatIter is the array based Iterator impelementation that converts an element to a slice and iterates over the elements of that slice. For example, FlatIter can be used to iterate over all the elements of a multi-dimensional array as if it were a one-dimensional array ([][]int -> []int).

func Flat

func Flat[FS ~[]From, From, To any](elements FS, flatter func(From) ([]To, error)) *FlatIter[From, To]

Flat instantiates an iterator that extracts slices of 'To' by a flattener from elements of 'From' and flattens as one iterable collection of 'To' elements.

func (*FlatIter[From, To]) Cap

func (f *FlatIter[From, To]) Cap() int

Cap returns the iterator capacity

func (*FlatIter[From, To]) For

func (f *FlatIter[From, To]) For(walker func(element To) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*FlatIter[From, To]) Next

func (f *FlatIter[From, To]) Next() (t To, ok bool, err error)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

type FlattIter

type FlattIter[From, To any] struct {
	// contains filtered or unexported fields
}

FlattIter is the array based Iterator impelementation that converts an element to a slice and iterates over the elements of that slice. For example, FlattIter can be used to iterate over all the elements of a multi-dimensional array as if it were a one-dimensional array ([][]int -> []int).

func Flatt

func Flatt[FS ~[]From, From, To any](elements FS, by func(From) []To) *FlattIter[From, To]

Flatt instantiates an iterator that extracts slices of 'To' by a flattener from elements of 'From' and flattens as one iterable collection of 'To' elements.

func (*FlattIter[From, To]) Cap

func (f *FlattIter[From, To]) Cap() int

Cap returns the iterator capacity

func (*FlattIter[From, To]) For

func (f *FlattIter[From, To]) For(walker func(element To) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*FlattIter[From, To]) ForEach

func (f *FlattIter[From, To]) ForEach(walker func(element To))

ForEach FlatIter all elements retrieved by the iterator

func (*FlattIter[From, To]) Next

func (f *FlattIter[From, To]) Next() (To, bool)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

type FlattenFitIter

type FlattenFitIter[From, To any] struct {
	// contains filtered or unexported fields
}

FlattenFitIter is the array based Iterator impelementation that converts an element to a slice with addition filtering of the element by a Predicate and iterates over the slice.

func FilterAndFlatt

func FilterAndFlatt[FS ~[]From, From, To any](elements FS, filter func(From) bool, flattener func(From) []To) *FlattenFitIter[From, To]

FilterAndFlatt filters source elements and extracts slices of 'To' by the 'flattener' function

func (*FlattenFitIter[From, To]) Cap

func (f *FlattenFitIter[From, To]) Cap() int

Cap returns the iterator capacity

func (*FlattenFitIter[From, To]) For

func (f *FlattenFitIter[From, To]) For(walker func(element To) error) error

For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*FlattenFitIter[From, To]) ForEach

func (f *FlattenFitIter[From, To]) ForEach(walker func(element To))

ForEach FlatIter all elements retrieved by the iterator

func (*FlattenFitIter[From, To]) Next

func (f *FlattenFitIter[From, To]) Next() (To, bool)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

type KeyValIter

type KeyValIter[T, K, V any] struct {
	// contains filtered or unexported fields
}

KeyValIter is the Iterator wrapper that converts an element to a key\value pair and iterates over these pairs

func NewKeyVal

func NewKeyVal[TS ~[]T, T any, K, V any](elements TS, keyExtractor func(T) (K, error), valsExtractor func(T) (V, error)) *KeyValIter[T, K, V]

NewKeyVal creates instance of the KeyValuer

func (*KeyValIter[T, K, V]) Next

func (kv *KeyValIter[T, K, V]) Next() (key K, value V, ok bool, err error)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

func (KeyValIter[T, K, V]) Track

func (kv KeyValIter[T, K, V]) Track(traker func(key K, value V) error) error

Track takes key, value pairs retrieved by the iterator. Can be interrupt by returning ErrBreak

type KeyValuerIter

type KeyValuerIter[T, K, V any] struct {
	// contains filtered or unexported fields
}

KeyValuerIter is the Iterator wrapper that converts an element to a key\value pair and iterates over these pairs

func NewKeyValuer

func NewKeyValuer[TS ~[]T, T any, K, V any](elements TS, keyExtractor func(T) K, valsExtractor func(T) V) *KeyValuerIter[T, K, V]

NewKeyValuer creates instance of the KeyValuer

func ToKV

func ToKV[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) *KeyValuerIter[T, K, V]

ToKV transforms iterable elements to key/value iterator based on applying key, value extractors to the elements

func (*KeyValuerIter[T, K, V]) Next

func (kv *KeyValuerIter[T, K, V]) Next() (key K, value V, ok bool)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

func (KeyValuerIter[T, K, V]) Track

func (kv KeyValuerIter[T, K, V]) Track(traker func(key K, value V) error) error

Track takes key, value pairs retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*KeyValuerIter[T, K, V]) TrackEach

func (kv *KeyValuerIter[T, K, V]) TrackEach(traker func(key K, value V))

TrackEach takes all key, value pairs retrieved by the iterator

type MultipleKeyValIter

type MultipleKeyValIter[T, K, V any] struct {
	// contains filtered or unexported fields
}

MultipleKeyValIter is the Iterator wrapper that converts an element to a key\value pair and iterates over these pairs

func (*MultipleKeyValIter[T, K, V]) Next

func (kv *MultipleKeyValIter[T, K, V]) Next() (key K, value V, ok bool, err error)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

func (*MultipleKeyValIter[T, K, V]) Track

func (kv *MultipleKeyValIter[T, K, V]) Track(traker func(key K, value V) error) error

Track takes key, value pairs retrieved by the iterator. Can be interrupt by returning ErrBreak

type MultipleKeyValuer

type MultipleKeyValuer[T, K, V any] struct {
	// contains filtered or unexported fields
}

MultipleKeyValuer is the Iterator wrapper that converts an element to a key\value pair and iterates over these pairs

func FlattKeys

func FlattKeys[TS ~[]T, T, K any](elements TS, keysExtractor func(T) []K) *MultipleKeyValuer[T, K, T]

FlattKeys transforms iterable elements to key/value iterator based on applying key, value extractor to the elements

func FlattValues

func FlattValues[TS ~[]T, T, V any](elements TS, valsExtractor func(T) []V) *MultipleKeyValuer[T, T, V]

FlattValues transforms iterable elements to key/value iterator based on applying key, value extractor to the elements

func NewMultipleKeyValuer

func NewMultipleKeyValuer[TS ~[]T, T any, K, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]

NewMultipleKeyValuer creates instance of the MultipleKeyValuer

func ToKVs

func ToKVs[TS ~[]T, T, K, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) *MultipleKeyValuer[T, K, V]

ToKVs transforms iterable elements to key/value iterator based on applying key, value extractor to the elements

func (*MultipleKeyValuer[T, K, V]) Next

func (kv *MultipleKeyValuer[T, K, V]) Next() (key K, value V, ok bool)

Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.

func (*MultipleKeyValuer[T, K, V]) Track

func (kv *MultipleKeyValuer[T, K, V]) Track(traker func(key K, value V) error) error

Track takes key, value pairs retrieved by the iterator. Can be interrupt by returning ErrBreak

func (*MultipleKeyValuer[T, K, V]) TrackEach

func (kv *MultipleKeyValuer[T, K, V]) TrackEach(traker func(key K, value V))

TrackEach takes all key, value pairs retrieved by the iterator

Jump to

Keyboard shortcuts

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