Documentation
¶
Overview ¶
Package seq2 extends iter.Seq2 API with convering, filtering, and reducing functionality.
Index ¶
- func AppendMapResolv[S ~Seq2[K, V], K comparable, V, VR any](seq S, resolver func(exists bool, key K, valResolv VR, val V) VR, ...) map[K]VR
- func AppendMapResolvOrder[S ~Seq2[K, V], K comparable, V, VR any](seq S, resolver func(exists bool, key K, valResolv VR, val V) VR, order []K, ...) ([]K, map[K]VR)
- func First[S ~Seq2[K, V], K, V any](seq S, condition func(K, V) bool) (k K, v V, ok bool)
- func Firstt[S ~Seq2[K, V], K, V any](seq S, condition func(K, V) (bool, error)) (k K, v V, ok bool, err error)
- func Group[S ~Seq2[K, V], K comparable, V any](seq S) map[K][]V
- func HasAny[S ~Seq2[K, V], K, V any](seq S, condition func(K, V) bool) bool
- func Head[S ~Seq2[K, V], K, V any](seq S) (k K, v V, ok bool)
- func MapResolv[S ~Seq2[K, V], K comparable, V, VR any](seq S, resolver func(exists bool, key K, valResolv VR, val V) VR) map[K]VR
- func MapResolvOrder[S ~Seq2[K, V], K comparable, V, VR any](seq S, resolver func(exists bool, key K, valResolv VR, val V) VR) ([]K, map[K]VR)
- func TrackEach[S ~Seq2[K, V], K, V any](seq S, consumer func(K, V))
- type Seq
- type Seq2
- func Convert[S ~Seq2[Kfrom, Vfrom], Kfrom, Vfrom, Kto, Vto any](seq S, converter func(Kfrom, Vfrom) (Kto, Vto)) Seq2[Kto, Vto]
- func ConvertKey[S ~Seq2[Kfrom, V], Kfrom, Kto, V any](seq S, converter func(Kfrom) Kto) Seq2[Kto, V]
- func ConvertValue[S ~Seq2[K, Vfrom], K, Vfrom, Vto any](seq S, converter func(Vfrom) Vto) Seq2[K, Vto]
- func Filt[S ~Seq2[K, V], K, V any](seq S, filter func(K, V) (bool, error)) Seq2[c.KV[K, V], error]
- func Filter[S ~Seq2[K, V], K, V any](seq S, filter func(K, V) bool) Seq2[K, V]
- func FilterKey[S ~Seq2[K, V], K, V any](seq S, filter func(K) bool) Seq2[K, V]
- func FilterValue[S ~Seq2[K, V], K, V any](seq S, filter func(V) bool) Seq2[K, V]
- func Union[S ~Seq2[K, V], K, V any](seq ...S) Seq2[K, V]
- type SeqE
- func Conv[S ~Seq2[Kfrom, Vfrom], Kfrom, Vfrom, Kto, Vto any](seq S, converter func(Kfrom, Vfrom) (Kto, Vto, error)) SeqE[c.KV[Kto, Vto]]
- func ConvKey[S ~Seq2[Kfrom, V], Kfrom, Kto, V any](seq S, converter func(Kfrom) (Kto, error)) SeqE[c.KV[Kto, V]]
- func ConvValue[S ~Seq2[K, Vfrom], K, Vfrom, Vto any](seq S, converter func(Vfrom) (Vto, error)) SeqE[c.KV[K, Vto]]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendMapResolv ¶
func AppendMapResolv[S ~Seq2[K, V], K comparable, V, VR any](seq S, resolver func(exists bool, key K, valResolv VR, val V) VR, dest map[K]VR) map[K]VR
AppendMapResolv collects key\value elements into the 'dest' map by iterating over the elements with resolving of duplicated key values.
func AppendMapResolvOrder ¶
func AppendMapResolvOrder[S ~Seq2[K, V], K comparable, V, VR any](seq S, resolver func(exists bool, key K, valResolv VR, val V) VR, order []K, dest map[K]VR) ([]K, map[K]VR)
AppendMapResolvOrder collects key\value elements into the 'dest' map by iterating over the elements with resolving of duplicated key values Additionally populates the 'order' slice by the keys ordered by the time they were added and the resolved key\value map.
func Firstt ¶
func Firstt[S ~Seq2[K, V], K, V any](seq S, condition func(K, V) (bool, error)) (k K, v V, ok bool, err error)
Firstt returns the first key\value pair that satisfies the condition.
func Group ¶
func Group[S ~Seq2[K, V], K comparable, V any](seq S) map[K][]V
Group collects the elements of the 'seq' sequence into a new map.
func MapResolv ¶
func MapResolv[S ~Seq2[K, V], K comparable, V, VR any](seq S, resolver func(exists bool, key K, valResolv VR, val V) VR) map[K]VR
MapResolv collects key\value elements into a new map by iterating over the elements with resolving of duplicated key values.
func MapResolvOrder ¶
func MapResolvOrder[S ~Seq2[K, V], K comparable, V, VR any](seq S, resolver func(exists bool, key K, valResolv VR, val V) VR) ([]K, map[K]VR)
MapResolvOrder collects key\value elements into a new map by iterating over the elements with resolving of duplicated key values. Returns a slice with the keys ordered by the time they were added and the resolved key\value map.
Types ¶
type Seq ¶
Seq is an iterator-function that allows to iterate over elements of a sequence, such as slice.
type Seq2 ¶
Seq2 is an iterator-function that allows to iterate over key/value pairs of a sequence, such as slice or map. It is used to iterate over slice index/value pairs or map key/value pairs.
func Convert ¶
func Convert[S ~Seq2[Kfrom, Vfrom], Kfrom, Vfrom, Kto, Vto any](seq S, converter func(Kfrom, Vfrom) (Kto, Vto)) Seq2[Kto, Vto]
Convert creates an iterator that applies the 'converter' function to each iterable key\value pair.
func ConvertKey ¶
func ConvertKey[S ~Seq2[Kfrom, V], Kfrom, Kto, V any](seq S, converter func(Kfrom) Kto) Seq2[Kto, V]
ConvertKey returns a seq that applies the 'converter' function to keys.
func ConvertValue ¶
func ConvertValue[S ~Seq2[K, Vfrom], K, Vfrom, Vto any](seq S, converter func(Vfrom) Vto) Seq2[K, Vto]
ConvertValue returns a seq that applies the 'converter' function to values.
func Filt ¶
Filt creates an erroreable iterator that iterates only those key\value pairs for which the 'filter' function returns true.
func Filter ¶
Filter creates an iterator that iterates only those elements for which the 'filter' function returns true.
func FilterKey ¶
FilterKey returns a seq consisting of key/value pairs where the key satisfies the condition of the 'filter' function.
func FilterValue ¶
FilterValue returns a seq consisting of key/value pairs where the value satisfies the condition of the 'filter' function.
type SeqE ¶
SeqE is a specific iterator form that allows to retrieve a value with an error as second parameter of the iterator. It is used as a result of applying functions like seq.Conv, which may throw an error during iteration. At each iteration step, it is necessary to check for the occurrence of an error.
for e, err := range seqence {
if err != nil {
break
}
...
}
func Conv ¶
func Conv[S ~Seq2[Kfrom, Vfrom], Kfrom, Vfrom, Kto, Vto any](seq S, converter func(Kfrom, Vfrom) (Kto, Vto, error)) SeqE[c.KV[Kto, Vto]]
Conv creates an errorable seq that applies the 'converter' function to the iterable key\value pairs.