seqe

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package seqe provides convering, filtering, and reducing operations for the [seq.SeqE] interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accum

func Accum[T any, S ~SeqE[T]](first T, seq S, merge func(T, T) T) (accumulator T, err error)

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

func Accumm[T any, S ~SeqE[T]](first T, seq S, merge func(T, T) (T, error)) (accumulator T, err error)

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 Append

func Append[S ~SeqE[T], T any, TS ~[]T](seq S, out TS) (TS, error)

Append collects the elements of the 'seq' sequence into the specified 'out' slice.

func First

func First[S ~SeqE[T], T any](seq S, predicate func(T) bool) (v T, ok bool, err error)

First returns the first element that satisfies the condition.

func Firstt

func Firstt[S ~SeqE[T], T any](seq S, predicate func(T) (bool, error)) (v T, ok bool, err error)

Firstt returns the first element that satisfies the condition.

func ForEach

func ForEach[T any](seq SeqE[T], consumer func(T)) error

ForEach applies the 'consumer' function to the seq elements

func HasAny

func HasAny[S ~SeqE[T], T any](seq S, predicate func(T) bool) (bool, error)

HasAny checks whether the seq contains an element that satisfies the condition.

func Head[S ~SeqE[T], T any](seq S) (v T, ok bool, err error)

Head returns the first element.

func Reduce

func Reduce[S ~SeqE[T], T any](seq S, merge func(T, T) T) (T, error)

Reduce reduces the elements of the seq into one using the 'merge' function.

func ReduceOK

func ReduceOK[S ~SeqE[T], T any](seq S, merge func(T, T) T) (result T, ok bool, err error)

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

func Reducee[S ~SeqE[T], T any](seq S, merge func(T, T) (T, error)) (T, error)

Reducee reduces the elements of the seq into one using the 'merge' function.

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 Slice

func Slice[S ~SeqE[T], T any](seq S) ([]T, error)

Slice collects the elements of the 'seq' sequence into a new slice.

func SliceCap

func SliceCap[S ~SeqE[T], T any](seq S, capacity int) (out []T, err error)

SliceCap collects the elements of the 'seq' sequence into a new slice with predefined capacity.

Types

type SeqE

type SeqE[T any] = func(func(T, error) bool)

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 ~SeqE[From], From, To any](seq S, converter func(From) (To, error)) SeqE[To]

Conv creates an errorable seq that applies the 'converter' function to the collection 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 Convert

func Convert[S ~SeqE[From], From, To any](seq S, converter func(From) To) SeqE[To]

Convert creates an iterator that applies the 'converter' function to each iterable element.

func Filt

func Filt[S ~SeqE[T], T any](seq S, filter func(T) (bool, error)) SeqE[T]

Filt creates an erroreable iterator that iterates only those elements for which the 'filter' function returns true.

func Filter

func Filter[S ~SeqE[T], T any](seq S, filter func(T) bool) SeqE[T]

Filter creates an iterator that iterates only those elements for which the 'filter' function returns true.

func Skip

func Skip[S ~SeqE[T], T any](n int, seq S) SeqE[T]

Skip returns the seq without first n elements.

func SkipWhile

func SkipWhile[S ~SeqE[T], T any](seq S, filter func(T) bool) SeqE[T]

SkipWhile returns a sequence without first elements of the seq that dont'math the filter.

func Top

func Top[S ~SeqE[T], T any](n int, seq S) SeqE[T]

Top returns a sequence of top n elements.

func Union

func Union[S ~SeqE[T], T any](seq ...S) SeqE[T]

Union combines several sequences into one.

func While

func While[S ~SeqE[T], T any](seq S, filter func(T) bool) SeqE[T]

While cuts tail elements of the seq that don't match the filter.

Jump to

Keyboard shortcuts

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