Documentation
¶
Overview ¶
Package iterhelper contains iter package helpers.
Index ¶
- Variables
- func ChanAll[E any](c <-chan E) iter.Seq[E]
- func ChanAll2[E any](c <-chan E) iter.Seq2[int, E]
- func Collect2[K, V any](seq2 iter.Seq2[K, V]) []any
- func Collect2Tuple[K, V any](seq2 iter.Seq2[K, V]) []generichelper.Tuple2[K, V]
- func Empty[V any]() iter.Seq[V]
- func Empty2[K, V any]() iter.Seq2[K, V]
- func Equal[V any](first, second iter.Seq[V]) (bool, error)
- func Equal2[K, V any](first, second iter.Seq2[K, V]) (bool, error)
- func EqualEq[V any](first, second iter.Seq[V], equal func(V, V) bool) (bool, error)
- func EqualEq2[K, V any](first, second iter.Seq2[K, V], equal func(k1 K, v1 V, k2 K, v2 V) bool) (bool, error)
- func ErrWrongType(got, want any) error
- func ForEach[V any](ctx context.Context, seq iter.Seq[V], action func(V) error) error
- func ForEach2[K, V any](ctx context.Context, seq2 iter.Seq2[K, V], action func(K, V) error) error
- func ForEachConcurrent[V any](ctx context.Context, seq iter.Seq[V], action func(V) error) error
- func ForEachConcurrent2[K, V any](ctx context.Context, seq2 iter.Seq2[K, V], action func(K, V) error) error
- func Seq2Seq[K, V, V2 any](seq2 iter.Seq2[K, V], selector func(K, V) V2) (iter.Seq[V2], error)
- func Seq2SeqK[K, V any](seq2 iter.Seq2[K, V]) (iter.Seq[K], error)
- func Seq2SeqV[K, V any](seq2 iter.Seq2[K, V]) (iter.Seq[V], error)
- func SeqSeq2[V, K2, V2 any](seq iter.Seq[V], selector func(V) (K2, V2)) (iter.Seq2[K2, V2], error)
- func StringDef[V any](seq iter.Seq[V]) string
- func StringDef2[K, V any](seq2 iter.Seq2[K, V]) string
- func StringFmt[V any](seq iter.Seq[V], format Format) string
- func StringFmt2[K, V any](seq2 iter.Seq2[K, V], format Format) string
- func StringSeq[V any](seq iter.Seq[V]) (iter.Seq[string], error)
- func StringSlice[V any](seq iter.Seq[V]) ([]string, error)
- func Var[V any](vv ...V) iter.Seq[V]
- func Var2[K, V any](vv ...any) (iter.Seq2[K, V], error)
- func Var2Tuple[K, V any](tt ...generichelper.Tuple2[K, V]) iter.Seq2[K, V]
- type Format
Constants ¶
This section is empty.
Variables ¶
var ( ErrOddValues = errors.New("odd number of values") ErrNilAction = errors.New("nil action") ErrNilEqual = errors.New("nil equal") ErrNilSec = errors.New("nil Sec") ErrNilSec2 = errors.New("nil Sec2") ErrNilSelector = errors.New("nil selector") )
var DefaultFormat = Format{
LeftRim: "",
RightRim: "",
ElementSeparator: " ",
LeftEdge: "[",
RightEdge: "]",
ValueSeparator: ":",
}
DefaultFormat represents default formatting parameters used by StringDef and StringDef2. Assign desired values, if needed.
Functions ¶
func ChanAll ¶ added in v0.5.0
ChanAll returns an iterator over the elements of the channel. If 'c' is nil, iterator over the empty sequence is returned.
func ChanAll2 ¶ added in v0.5.0
ChanAll2 returns an iterator over index-element pairs of the channel. If 'c' is nil, iterator over the empty sequence of pairs is returned.
func Collect2 ¶ added in v0.8.0
Collect2 returns a slice of values collected from the iterator. Each pair of values yielded by the iterator results in two values in the slice. If 'seq2' is nil, nil is returned.
func Collect2Tuple ¶ added in v0.9.0
func Collect2Tuple[K, V any](seq2 iter.Seq2[K, V]) []generichelper.Tuple2[K, V]
Collect2Tuple returns a slice of tuples of values collected from the iterator. If 'seq2' is nil, nil is returned.
func Equal ¶ added in v0.6.0
Equal determines whether two iterators yield the equal sequences by comparing their elements using generichelper.DeepEqual.
func Equal2 ¶ added in v0.6.0
Equal2 determines whether two iterators yield the equal sequences by comparing their elements using reflect.DeepEqual.
func EqualEq ¶ added in v0.6.0
EqualEq determines whether two iterators yield the equal sequences by comparing their elements using a specified function.
func EqualEq2 ¶ added in v0.6.0
func EqualEq2[K, V any](first, second iter.Seq2[K, V], equal func(k1 K, v1 V, k2 K, v2 V) bool) (bool, error)
EqualEq2 determines whether two iterators yield the equal sequences by comparing their elements using a specified function.
func ErrWrongType ¶ added in v0.7.0
func ForEach ¶ added in v0.2.0
ForEach sequentially performs a specified 'action' on each value yielded by the iterator. If 'ctx' is canceled or 'action' returns a non-nil error, the operation is stopped and corresponding error is returned.
func ForEach2 ¶ added in v0.6.0
ForEach2 sequentially performs a specified 'action' on each pair of values yielded by the iterator. If 'ctx' is canceled or 'action' returns a non-nil error, the operation is stopped and corresponding error is returned.
func ForEachConcurrent ¶ added in v0.2.0
ForEachConcurrent concurrently performs a specified 'action' on each value yielded by the iterator. If 'ctx' is canceled or 'action' returns a non-nil error, the operation is stopped and corresponding error is returned.
func ForEachConcurrent2 ¶ added in v0.6.0
func ForEachConcurrent2[K, V any](ctx context.Context, seq2 iter.Seq2[K, V], action func(K, V) error) error
ForEachConcurrent2 concurrently performs a specified 'action' on each pair of values yielded by the iterator. If 'ctx' is canceled or 'action' returns a non-nil error, the operation is stopped and corresponding error is returned.
func StringDef ¶ added in v0.2.0
StringDef returns string representation of a sequence of values by calling fmt.Sprint on each value yielded by the iterator and using default formatting parameters. If 'seq' is nil, empty string is returned.
func StringDef2 ¶ added in v0.2.0
StringDef2 returns string representation of a sequence of pairs of values by calling fmt.Sprint on each value yielded by the iterator and using default formatting parameters. If 'seq2' is nil, empty string is returned.
func StringFmt ¶ added in v0.2.0
StringFmt returns string representation of a sequence of values by calling fmt.Sprint on each value yielded by the iterator. If 'seq' is nil, empty string is returned.
func StringFmt2 ¶ added in v0.2.0
StringFmt2 returns string representation of a sequence of pairs of values by calling fmt.Sprint on each value yielded by the iterator: If 'seq2' is nil, empty string is returned.
func StringSeq ¶ added in v0.2.0
StringSeq converts an iterator to an iterator over strings by calling fmt.Sprint on each value yielded by the iterator.
func StringSlice ¶ added in v0.2.0
StringSlice returns a sequence of values yielded by the iterator as a slice of strings.
Types ¶
type Format ¶ added in v0.9.0
type Format struct {
// Left and right rims surround each element of a sequence.
LeftRim, RightRim string
// Element separator separates elements of a sequence.
ElementSeparator string
// Left and right edges surround the whole string.
LeftEdge, RightEdge string
// Value separator separates values in pair.
ValueSeparator string
}
Format defines formatting parameters.