iterhelper

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 9 Imported by: 1

README

iterhelper

Go Reference

Helpers for Go's iter package.

Documentation

Overview

Package iterhelper contains iter package helpers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilAction   = errors.New("nil action")
	ErrNilEqual    = errors.New("nil equal")
	ErrNilSelector = errors.New("nil selector")
	ErrNilSource   = errors.New("nil source")
)

Functions

func Empty added in v0.2.0

func Empty[Result any]() iter.Seq[Result]

Empty returns an iterator over an empty sequence of values.

func Empty2 added in v0.2.0

func Empty2[K, V any]() iter.Seq2[K, V]

Empty2 returns an iterator over an empty sequence of pairs of values.

func ForEach added in v0.2.0

func ForEach[T any](ctx context.Context, seq iter.Seq[T], action func(T) error) error

ForEach sequentially performs a specified 'action' on each element of the sequence. If 'ctx' is canceled or 'action' returns non-nil error, operation is stopped and corresponding error is returned.

func ForEachConcurrent added in v0.2.0

func ForEachConcurrent[T any](ctx context.Context, seq iter.Seq[T], action func(T) error) error

ForEachConcurrent concurrently performs a specified 'action' on each element of the sequence. If 'ctx' is canceled or 'action' returns non-nil error, operation is stopped and corresponding error is returned.

func Seq2Seq added in v0.3.0

func Seq2Seq[K, V, V2 any](seq2 iter.Seq2[K, V], selector func(K, V) V2) (iter.Seq[V2], error)

Seq2Seq converts iter.Seq2 to iter.Seq.

func Seq2SeqK added in v0.3.0

func Seq2SeqK[K, V any](seq2 iter.Seq2[K, V]) (iter.Seq[K], error)

Seq2SeqK converts iter.Seq2 to iterator over keys of 'seq2'.

func Seq2SeqV added in v0.3.0

func Seq2SeqV[K, V any](seq2 iter.Seq2[K, V]) (iter.Seq[V], error)

Seq2SeqV converts iter.Seq2 to iterator over values of 'seq2'.

func SeqSeq2 added in v0.3.0

func SeqSeq2[V, K2, V2 any](seq iter.Seq[V], selector func(V) (K2, V2)) (iter.Seq2[K2, V2], error)

SeqSeq2 converts iter.Seq to iter.Seq2.

func SequenceEqual added in v0.2.0

func SequenceEqual[Source any](first, second iter.Seq[Source]) (bool, error)

SequenceEqual determines whether two sequences are equal by comparing their elements using generichelper.DeepEqual.

func SequenceEqual2 added in v0.2.0

func SequenceEqual2[K, V any](first, second iter.Seq2[K, V]) (bool, error)

SequenceEqual2 determines whether two sequences are equal by comparing their elements using generichelper.DeepEqual.

func SequenceEqual2Eq added in v0.2.0

func SequenceEqual2Eq[K, V any](first, second iter.Seq2[K, V], equalK func(K, K) bool, equalV func(V, V) bool) (bool, error)

SequenceEqual2Eq determines whether two sequences are equal by comparing their elements using specified equals.

func SequenceEqualEq added in v0.2.0

func SequenceEqualEq[Source any](first, second iter.Seq[Source], equal func(Source, Source) bool) (bool, error)

SequenceEqualEq determines whether two sequences are equal by comparing their elements using a specified function.

func StringDef added in v0.2.0

func StringDef[T any](seq iter.Seq[T]) string

StringDef returns string representation of a sequence using default formatting. If 'seq' is nil, empty string is returned.

func StringDef2 added in v0.2.0

func StringDef2[K, V any](seq2 iter.Seq2[K, V]) string

StringDef2 returns string representation of a sequence using default formatting. If 'seq2' is nil, empty string is returned.

func StringFmt added in v0.2.0

func StringFmt[T any](seq iter.Seq[T], sep, lrim, rrim, ledge, redge string) string

StringFmt returns string representation of a sequence:

  • if 'seq' is nil, empty string is returned;
  • if 'T' implements fmt.Stringer, it is used to convert each element to string;
  • 'sep' separates elements;
  • 'lrim' and 'rrim' surround each element;
  • 'ledge' and 'redge' surround the whole string.

func StringFmt2 added in v0.2.0

func StringFmt2[K, V any](seq2 iter.Seq2[K, V], psep, esep, lrim, rrim, ledge, redge string) string

StringFmt2 returns string representation of a sequence:

  • if 'seq2' is nil, empty string is returned;
  • if 'T' implements fmt.Stringer, it is used to convert each element to string;
  • 'psep' separates pair of values;
  • 'esep' separates elements;
  • 'lrim' and 'rrim' surround each element;
  • 'ledge' and 'redge' surround the whole string.

func StringSeq added in v0.2.0

func StringSeq[T any](seq iter.Seq[T]) (iter.Seq[string], error)

StringSeq converts a sequence to a sequence of strings.

func StringSlice added in v0.2.0

func StringSlice[T any](seq iter.Seq[T]) ([]string, error)

StringSlice returns a sequence contents as a slice of strings.

func VarSeq added in v0.3.0

func VarSeq[E any](s ...E) iter.Seq[E]

VarSeq returns an iterator over the variadic parameters.

func VarSeq2 added in v0.3.0

func VarSeq2[K, V any](tt ...generichelper.Tuple2[K, V]) iter.Seq2[K, V]

VarSeq2 returns an iterator over the variadic tuples.

Types

This section is empty.

Jump to

Keyboard shortcuts

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