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 Conv[S ~Seq2[Kfrom, Vfrom], Kfrom, Vfrom, Kto, Vto any](seq S, converter func(Kfrom, Vfrom) (Kto, Vto, error)) seq.SeqE[c.KV[Kto, Vto]]
- func ConvKey[S ~Seq2[Kfrom, V], Kfrom, Kto, V any](seq S, converter func(Kfrom) (Kto, error)) seq.SeqE[c.KV[Kto, V]]
- func ConvValue[S ~Seq2[K, Vfrom], K, Vfrom, Vto any](seq S, converter func(Vfrom) (Vto, error)) seq.SeqE[c.KV[K, Vto]]
- func Convert[S ~Seq2[Kfrom, Vfrom], Kfrom, Vfrom, Kto, Vto any](seq S, converter func(Kfrom, Vfrom) (Kto, Vto)) seq.Seq2[Kto, Vto]
- func ConvertKey[S ~Seq2[Kfrom, V], Kfrom, Kto, V any](seq S, converter func(Kfrom) Kto) seq.Seq2[Kto, V]
- func ConvertValue[S ~Seq2[K, Vfrom], K, Vfrom, Vto any](seq S, converter func(Vfrom) Vto) seq.Seq2[K, Vto]
- func Filt[S ~Seq2[K, V], K, V any](seq S, filter func(K, V) (bool, error)) seq.SeqE[c.KV[K, V]]
- func Filter[S ~Seq2[K, V], K, V any](seq S, filter func(K, V) bool) seq.Seq2[K, V]
- func FilterKey[S ~Seq2[K, V], K, V any](seq S, filter func(K) bool) seq.Seq2[K, V]
- func FilterValue[S ~Seq2[K, V], K, V any](seq S, filter func(V) bool) seq.Seq2[K, V]
- 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, filter 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, filter func(K, V) bool) bool
- func Head[S ~Seq2[K, V], K, V any](seq S) (k K, v V, ok bool)
- func Keys[S ~Seq2[K, V], K, V any](seq S) seq.Seq[K]
- func Map[S ~Seq2[K, V], K comparable, V any](seq S) map[K]V
- 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 Of[K, V any](elements ...c.KV[K, V]) seq.Seq2[K, V]
- func OfIndexed[T any](amount int, getAt func(int) T) seq.Seq2[int, T]
- func OfIndexedKV[K, V any](amount int, getAt func(int) (K, V)) seq.Seq2[K, V]
- func OfIndexedPair[K, V any](amount int, getKey func(int) K, getValue func(int) V) seq.Seq2[K, V]
- func OfMap[K comparable, V any](elements map[K]V) seq.Seq2[K, V]
- func Range[T constraints.Integer | rune](from T, toExclusive T) seq.Seq2[int, T]
- func RangeClosed[T constraints.Integer | rune](from T, toInclusive T) seq.Seq2[int, T]
- func Reduce[S ~Seq2[K, V], K, V, T any](seq S, merge func(prev *T, k K, v V) T) T
- func ReduceOK[S ~Seq2[K, V], K, V, T any](seq S, merge func(prev *T, k K, v V) T) (result T, ok bool)
- func Reducee[S ~Seq2[K, V], K, V, T any](seq S, merge func(prev *T, k K, v V) (T, error)) (T, error)
- func ReduceeOK[S ~Seq2[K, V], K, V, T any](seq S, merge func(prev *T, k K, v V) (T, error)) (result T, ok bool, err error)
- func Series[T any](first T, next func(int, T) (T, bool)) seq.Seq2[int, T]
- func Skip[S ~Seq2[K, V], K, V any](n int, seq S) seq.Seq2[K, V]
- func SkipWhile[S ~Seq2[K, V], K, V any](seq S, filter func(K, V) bool) seq.Seq2[K, V]
- func ToSeq[S ~Seq2[K, V], T, K, V any](seq S, converter func(K, V) T) seq.Seq[T]
- func Top[S ~Seq2[K, V], K, V any](n int, seq S) S
- func TrackEach[S ~Seq2[K, V], K, V any](seq S, consumer func(K, V))
- func Union[S ~Seq2[K, V], K, V any](seq ...S) seq.Seq2[K, V]
- func Values[S ~Seq2[K, V], K, V any](seq S) seq.Seq[V]
- func While[S ~Seq2[K, V], K, V any](seq S, filter func(K, V) bool) seq.Seq2[K, V]
- type Seq2
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 Conv ¶ added in v0.0.17
func Conv[S ~Seq2[Kfrom, Vfrom], Kfrom, Vfrom, Kto, Vto any](seq S, converter func(Kfrom, Vfrom) (Kto, Vto, error)) seq.SeqE[c.KV[Kto, Vto]]
Conv creates an errorable seq that applies the 'converter' function to the iterable key\value pairs.
func ConvKey ¶ added in v0.0.17
func ConvKey[S ~Seq2[Kfrom, V], Kfrom, Kto, V any](seq S, converter func(Kfrom) (Kto, error)) seq.SeqE[c.KV[Kto, V]]
ConvKey returns a seq that applies the 'converter' function to keys.
func ConvValue ¶ added in v0.0.17
func ConvValue[S ~Seq2[K, Vfrom], K, Vfrom, Vto any](seq S, converter func(Vfrom) (Vto, error)) seq.SeqE[c.KV[K, Vto]]
ConvValue returns a seq that applies the 'converter' function to values.
func Convert ¶
func Convert[S ~Seq2[Kfrom, Vfrom], Kfrom, Vfrom, Kto, Vto any](seq S, converter func(Kfrom, Vfrom) (Kto, Vto)) seq.Seq2[Kto, Vto]
Convert creates an iterator that applies the 'converter' function to each iterable element.
func ConvertKey ¶ added in v0.0.17
func ConvertKey[S ~Seq2[Kfrom, V], Kfrom, Kto, V any](seq S, converter func(Kfrom) Kto) seq.Seq2[Kto, V]
ConvertKey returns a seq that applies the 'converter' function to keys.
func ConvertValue ¶ added in v0.0.17
func ConvertValue[S ~Seq2[K, Vfrom], K, Vfrom, Vto any](seq S, converter func(Vfrom) Vto) seq.Seq2[K, Vto]
ConvertValue returns a seq that applies the 'converter' function to values.
func Filt ¶ added in v0.0.17
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 ¶ added in v0.0.17
FilterKey returns a seq consisting of key/value pairs where the key satisfies the condition of the 'filter' function.
func FilterValue ¶ added in v0.0.17
FilterValue returns a seq consisting of key/value pairs where the value satisfies the condition of the 'filter' function.
func Firstt ¶ added in v0.0.17
func Firstt[S ~Seq2[K, V], K, V any](seq S, filter 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 HasAny ¶ added in v0.0.17
HasAny checks whether the seq contains an element that satisfies the condition.
func Map ¶
func Map[S ~Seq2[K, V], K comparable, V any](seq S) map[K]V
Map collects key\value elements into a new map by iterating over the elements.
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.
func OfIndexed ¶ added in v0.0.15
OfIndexed builds an indexed Seq2 iterator by extracting elements from an indexed source. the len is length ot the source. the getAt retrieves an element by its index from the source.
func OfIndexedKV ¶ added in v0.0.17
OfIndexedKV builds an indexed Seq2 iterator by extracting key\value pairs from an indexed source. the len is length ot the source. the getAt retrieves a key\value pair by its index from the source.
func OfIndexedPair ¶ added in v0.0.17
OfIndexedPair builds an indexed Seq2 iterator by extracting key\value pairs from an indexed source. the len is length ot the source. the getKey retrieves a key by its index from the source. the getValue retrieves a value by its index from the source.
func OfMap ¶
func OfMap[K comparable, V any](elements map[K]V) seq.Seq2[K, V]
OfMap creates an key/value pairs iterator over the elements map.
func Range ¶ added in v0.0.15
Range creates a sequence that generates integers in the range defined by from and to exclusive.
func RangeClosed ¶ added in v0.0.15
RangeClosed creates a sequence that generates integers in the range defined by from and to inclusive
func Reduce ¶ added in v0.0.16
Reduce reduces the elements of the seq into one using the 'merge' function.
func ReduceOK ¶ added in v0.0.16
func ReduceOK[S ~Seq2[K, V], K, V, T any](seq S, merge func(prev *T, k K, v V) T) (result T, ok bool)
ReduceOK reduces the elements of the seq into one using the 'merge' function. Returns ok==false if the seq returns ok=false at the first call (no more elements).
func Reducee ¶ added in v0.0.16
func Reducee[S ~Seq2[K, V], K, V, T any](seq S, merge func(prev *T, k K, v V) (T, error)) (T, error)
Reducee reduces the elements of the seq into one using the 'merge' function.
func ReduceeOK ¶ added in v0.0.16
func ReduceeOK[S ~Seq2[K, V], K, V, T any](seq S, merge func(prev *T, k K, v V) (T, error)) (result T, ok bool, err error)
ReduceeOK reduces the elements of the seq into one using the 'merge' function. Returns ok==false if the seq returns ok=false at the first call (no more elements).
func Series ¶ added in v0.0.15
Series makes a sequence by applying the 'next' function to the previous step generated value.
func SkipWhile ¶ added in v0.0.16
SkipWhile returns a sequence without first elements of the seq that dont'math the filter.
func ToSeq ¶ added in v0.0.16
ToSeq converts an iterator of key/value pairs elements to an iterator of single elements by applying the 'converter' function to each iterable pair.