Documentation
¶
Overview ¶
Package seqe provides convering, filtering, and reducing operations for the seq.SeqE interface.
Index ¶
- func Accum[T any, S ~SeqE[T]](first T, seq S, merge func(T, T) T) (T, error)
- func Accumm[T any, S ~SeqE[T]](first T, seq S, merge func(T, T) (T, error)) (T, error)
- func Append[S ~SeqE[T], T any, TS ~[]T](seq S, out TS) (TS, error)
- func Contains[S ~SeqE[T], T comparable](seq S, example T) (contains bool, err error)
- func Conv[S ~SeqE[From], From, To any](seq S, converter func(From) (To, error)) seq.SeqE[To]
- func ConvOK[S ~SeqE[From], From, To any](seq S, converter func(from From) (To, bool, error)) seq.SeqE[To]
- func Convert[S ~SeqE[From], From, To any](seq S, converter func(From) To) seq.SeqE[To]
- func ConvertNilSafe[S ~SeqE[*From], From, To any](seq S, converter func(*From) *To) seq.SeqE[*To]
- func ConvertOK[S ~SeqE[From], From, To any](seq S, converter func(from From) (To, bool)) seq.SeqE[To]
- func Filt[S ~SeqE[T], T any](seq S, filter func(T) (bool, error)) seq.SeqE[T]
- func Filter[S ~SeqE[T], T any](seq S, filter func(T) bool) seq.SeqE[T]
- func First[S ~SeqE[T], T any](seq S, condition func(T) bool) (v T, ok bool, err error)
- func Firstt[S ~SeqE[T], T any](seq S, condition func(T) (bool, error)) (v T, ok bool, err error)
- func Flat[S ~SeqE[From], STo ~[]To, From any, To any](seq S, flattener func(From) STo) seq.SeqE[To]
- func FlatSeq[S ~SeqE[From], STo ~Seq[To], From any, To any](seq S, flattener func(From) STo) seq.SeqE[To]
- func Flatt[S ~SeqE[From], STo ~[]To, From any, To any](seq S, flattener func(From) (STo, error)) seq.SeqE[To]
- func FlattSeq[S ~SeqE[From], STo ~SeqE[To], From any, To any](seq S, flattener func(From) STo) seq.SeqE[To]
- func ForEach[T any](seq SeqE[T], consumer func(T)) error
- func Group[S ~SeqE[T], T any, K comparable, V any](seq S, keyExtractor func(T) K, valExtractor func(T) V) (map[K][]V, error)
- func HasAny[S ~SeqE[T], T any](seq S, condition func(T) bool) (bool, error)
- func Head[S ~SeqE[T], T any](seq S) (v T, ok bool, err error)
- func NotNil[T any](seq SeqE[*T]) seq.SeqE[*T]
- func OfIndexed[T any](amount int, getAt func(int) (T, error)) seq.SeqE[T]
- func OfNext[T any](hasNext func() bool, pushNext func(*T) error) seq.SeqE[T]
- func OfNextGet[T any](hasNext func() bool, getNext func() (T, error)) seq.SeqE[T]
- func OfSourceNext[S, T any](source S, hasNext func(S) bool, pushNext func(S, *T) error) seq.SeqE[T]
- func OfSourceNextGet[S, T any](source S, hasNext func(S) bool, getNext func(S) (T, error)) seq.SeqE[T]
- func Reduce[S ~SeqE[T], T any](seq S, merge func(T, T) T) (T, error)
- func ReduceOK[S ~SeqE[T], T any](seq S, merge func(T, T) T) (result T, ok bool, err error)
- func Reducee[S ~SeqE[T], T any](seq S, merge func(T, T) (T, error)) (T, error)
- func ReduceeOK[S ~SeqE[T], T any](seq S, merge func(T, T) (T, error)) (result T, ok bool, err error)
- func Skip[S ~SeqE[T], T any](n int, seq S) seq.SeqE[T]
- func SkipWhile[S ~SeqE[T], T any](seq S, filter func(T) bool) seq.SeqE[T]
- func Slice[S ~SeqE[T], T any](seq S) ([]T, error)
- func SliceCap[S ~SeqE[T], T any](seq S, capacity int) (out []T, e error)
- func Sum[S ~SeqE[T], T op.Summable](seq S) (out T, err error)
- func Top[S ~SeqE[T], T any](n int, seq S) seq.SeqE[T]
- func Union[S ~SeqE[T], T any](seq ...S) seq.SeqE[T]
- func While[S ~SeqE[T], T any](seq S, filter func(T) bool) seq.SeqE[T]
- type Seq
- type SeqE
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accum ¶
Accum accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element of the 'seq' sequence.
func Accumm ¶
Accumm accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element of the 'seq' sequence.
func Contains ¶
func Contains[S ~SeqE[T], T comparable](seq S, example T) (contains bool, err error)
Contains finds the first element that equal to the example and returns true.
func Conv ¶
Conv creates an errorable seq that applies the 'converter' function to the iterable elements. The error should be checked at every iteration step, like:
var integers iter.Seq2[int, error]
...
for s, err := range seqe.Conv(integers, strconv.Itoa) {
if err != nil {
break
}
...
}
func ConvOK ¶
func ConvOK[S ~SeqE[From], From, To any](seq S, converter func(from From) (To, bool, error)) seq.SeqE[To]
ConvOK creates a iterator that applies the 'converter' function to each iterable element. The converter may returns a value or ok=false to exclude the value from iteration. It may also return an error to abort the iteration.
func Convert ¶
Convert creates an iterator that applies the 'converter' function to each iterable element.
func ConvertNilSafe ¶ added in v0.0.17
ConvertNilSafe creates a seq that filters not nil elements, converts that ones, filters not nils after converting and returns them.
func ConvertOK ¶
func ConvertOK[S ~SeqE[From], From, To any](seq S, converter func(from From) (To, bool)) seq.SeqE[To]
ConvertOK creates an iterator that applies the 'converter' function to each iterable element. The converter may returns a value or ok=false to exclude the value from the sequence.
func Filt ¶
Filt creates an erroreable iterator that iterates only those elements 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 Flat ¶
Flat is used to iterate over a two-dimensional sequence in single dimension form, like:
var arrays seq.SeqE[[]int]
...
for e, err := range seqe.Flat(arrays, as.Is) {
if err != nil {
panic(err)
}
}
func FlatSeq ¶
func FlatSeq[S ~SeqE[From], STo ~Seq[To], From any, To any](seq S, flattener func(From) STo) seq.SeqE[To]
FlatSeq is used to iterate over a two-dimensional sequence in single dimension form, like:
var arrays seq.SeqE[[]int]
...
for e, err := range seqe.FlatSeq(arrays, slices.Values) {
if err != nil {
panic(err)
}
}
func Flatt ¶
func Flatt[S ~SeqE[From], STo ~[]To, From any, To any](seq S, flattener func(From) (STo, error)) seq.SeqE[To]
Flatt is used to iterate over a two-dimensional sequence in single dimension form, like:
var (
input iter.Seq[[]string]
flattener func([]string) ([]int, error)
out seq.SeqE[int]
)
flattener = convertEveryBy(strconv.Atoi)
out = seq.Flatt(input, flattener)
for i, err := range out {
if err != nil {
panic(err)
}
...
}
func FlattSeq ¶
func FlattSeq[S ~SeqE[From], STo ~SeqE[To], From any, To any](seq S, flattener func(From) STo) seq.SeqE[To]
FlattSeq is used to iterate over a two-dimensional sequence in single dimension form, like:
var (
input iter.Seq[[]string]
flattener func([]string) seq.SeqE[int]
out seq.SeqE[int]
)
flattener = convertEveryBy(strconv.Atoi)
out = seq.Flatt(input, flattener)
for i, err := range out {
if err != nil {
panic(err)
}
...
}
func Group ¶
func Group[S ~SeqE[T], T any, K comparable, V any](seq S, keyExtractor func(T) K, valExtractor func(T) V) (map[K][]V, error)
Group collects the seq elements into a new map. The keyExtractor converts an element to a key. The valExtractor converts an element to a value.
func OfIndexed ¶
OfIndexed builds a SeqE 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 OfNext ¶
OfNext builds an iterator by iterating elements of a source. The hasNext specifies a predicate that tests existing of a next element in the source. The pushNext copy the element to the next pointer.
func OfNextGet ¶
OfNextGet builds an iterator by iterating elements of a source. The hasNext specifies a predicate that tests existing of a next element in the source. The getNext extracts the element.
func OfSourceNext ¶
OfSourceNext builds an iterator by iterating elements of the source. The hasNext specifies a predicate that tests existing of a next element in the source. The pushNext copy the element to the next pointer.
func OfSourceNextGet ¶
func OfSourceNextGet[S, T any](source S, hasNext func(S) bool, getNext func(S) (T, error)) seq.SeqE[T]
OfSourceNextGet builds an iterator by iterating elements of the source. The hasNext specifies a predicate that tests existing of a next element in the source. The getNext extracts the element.
func ReduceOK ¶
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 ReduceeOK ¶
func ReduceeOK[S ~SeqE[T], T any](seq S, merge func(T, T) (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 SkipWhile ¶ added in v0.0.17
SkipWhile returns a sequence without first elements of the seq that dont'math the filter.
func SliceCap ¶
SliceCap collects the elements of the 'seq' sequence into a new slice with predefined capacity.
Types ¶
type Seq ¶
Seq is an iterator-function that allows to iterate over elements of a sequence, such as slice.
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
}
...
}