gi

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 4 Imported by: 0

README

gi GoDoc Build Status Coverage Status

Module gi provides a set of generic iterator combinators and corresponding helpers.

Packages

  • gi

    Package gi provides a set of generic iterator combinators over scalar values iter.Seq.

  • gi2

    Package gi2 provides a set of generic iterator combinators over pairs of values iter.Seq2.

  • giopt

    Package giopt provides a set of generic iterator combinators over scalar values iter.Seq adapted for optval.Value.

  • gi2opt

    Package gi2opt provides a set of generic iterator combinators over pairs of values iter.Seq adapted for optpair.Pair.

  • giop

    Package giop provides a set of binary operators on scalar values for generic iterator combinators.

  • gi2op

    Package gi2op provides a set of binary operators on pairs of values for generic iterator combinators.

Documentation

Overview

Package gi provides a set of generic iterator combinators over scalar values iter.Seq.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And[T any, P constraints.Predicate[T]](predicates ...P) P

And returns a predicate that returns true only in case all of the given predicates return true. And returns true if there are no given predicates.

func Any added in v0.4.0

func Any[T any, F constraints.Predicate[T]](predicate F) func(iter.Seq[T]) bool

Any returns a predicate that takes a sequence of values and returns true in case any of the values in the sequence satisfy the given predicate.

func Chunk

func Chunk[V any, I constraints.Integer](values iter.Seq[V], size I) iter.Seq[iter.Seq[V]]

Chunk returns an iterator that yields chunks of size elements from the given values.

func ChunkToSlices

func ChunkToSlices[V any](values iter.Seq[V], size int) iter.Seq[[]V]

ChunkToSlices returns a new iterator that yields slices of size elements from the given values.

func Cloned

func Cloned[V constraints.Cloneable[C], C any](values iter.Seq[V]) iter.Seq[C]

Cloned returns a new iterator that consumes original iterator and clones each value.

func Concat

func Concat[V any](values ...iter.Seq[V]) iter.Seq[V]

Concat returns an iterator that concatenates the values of the given iterators.

func ConcatSlices

func ConcatSlices[V any, VV ~[]V](values ...VV) iter.Seq[V]

ConcatSlices returns an iterator that over concatenation of the given slices.

func Contains

func Contains[V any, P constraints.Predicate[V]](values iter.Seq[V], predicate P) bool

Contains returns true if the given values contain a value matching the predicate.

func Count

func Count[V any](values iter.Seq[V]) int

Count returns the number of values in the sequence.

func DivisibleBy

func DivisibleBy[T constraints.Integer](divisor T) func(value T) bool

DivisibleBy returns a predicate that returns true if its argument can be divided by the given divisor without a remainder.

func Each added in v0.4.0

func Each[T any, F constraints.Predicate[T]](predicate F) func(iter.Seq[T]) bool

Each returns a predicate that takes a sequence of values and returns true in case all of the values in the sequence satisfy the given predicate.

func Empty added in v0.4.0

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

Empty returns an iterator that yields nothing.

func Enumerate added in v0.4.0

func Enumerate[V any](values iter.Seq[V]) iter.Seq2[int, V]

Enumerate returns an iterator over the given values, yielding pairs of the index and the value.

func EnumerateFrom added in v0.4.0

func EnumerateFrom[V any, I constraints.Integer](begin I, values iter.Seq[V]) iter.Seq2[I, V]

EnumerateFrom returns an iterator over the given values, yielding pairs of the index and the value. The index starts from the given begin value.

func Equal

func Equal[T comparable](value T) func(T) bool

Equal returns a predicate that returns true in case its argument is equal to the value.

func Even

func Even[T constraints.Integer](value T) bool

Even returns true if the value can be divided by 2 without a remainder.

func Every

func Every[V any, P constraints.Predicate[V]](values iter.Seq[V], predicate P) bool

Every returns true if all values match the predicate.

func Filter

func Filter[V any, P constraints.Predicate[V]](values iter.Seq[V], predicate P) iter.Seq[V]

Filter returns an iterator adapter that uses a predicate to filter values.

func FilterMap added in v0.4.0

func FilterMap[V, R any, F func(V) (R, bool)](values iter.Seq[V], f F) iter.Seq[R]

FilterMap returns an iterator that yields values by applying the provided filter-map function to values. The filter-map function returns an optional value. If the optional value is empty, the value is skipped.

func FilterMapWith added in v0.4.0

func FilterMapWith[V, R any, F func(V) (R, bool)](f F) func(values iter.Seq[V]) iter.Seq[R]

FilterMapWith returns a function that can be used to filter-map sequences of values. It uses the provided filter-map function to transform and filter values. If the optional value is empty, the value is skipped.

func FilterWith added in v0.4.0

func FilterWith[V any, P constraints.Predicate[V]](predicate P) func(iter.Seq[V]) iter.Seq[V]

FilterWith returns a function that filters an iterator sequence over values using a predicate.

func Find

func Find[V any, P constraints.Predicate[V]](values iter.Seq[V], predicate P) (V, bool)

Find returns the first value among the values matching the predicate.

func FindWith added in v0.4.0

func FindWith[V any, P constraints.Predicate[V]](predicate P) func(iter.Seq[V]) (V, bool)

FindWith returns a function that finds the first value among the values matching the predicate.

func Flatten

func Flatten[V any](values iter.Seq[iter.Seq[V]]) iter.Seq[V]

Flatten returns an iterator that flattens the values of the given iterator.

func FlattenBy

func FlattenBy[VV any, V any, F ~func(VV) iter.Seq[V]](values iter.Seq[VV], f F) iter.Seq[V]

FlattenBy returns an iterator that flattens the values of the given iterator using the provided function.

func FlattenSlices

func FlattenSlices[V any, VV ~[]V](values iter.Seq[VV]) iter.Seq[V]

FlattenSlices returns an iterator that flattens the slices of the given iterator.

func Fold

func Fold[V, R any, F ~func(R, V) R](values iter.Seq[V], initial R, accumulate F) R

Fold reduces the slice of values to a value which is the accumulated result of running accumulate function on each element where each successive invocation is supplied the return value of the previous one.

func FoldWith added in v0.4.0

func FoldWith[V, R any, F ~func(R, V) R](initial R, accumulate F) func(iter.Seq[V]) R

FoldWith returns a function that can be used to fold sequences of values.

func Greater

func Greater[T constraints.Ordered](value T) func(T) bool

Greater returns a predicate that returns true in case its argument is greater than the value.

func GreaterOrEqual

func GreaterOrEqual[T constraints.Ordered](value T) func(T) bool

GreaterOrEqual returns a predicate that returns true in case its argument is greater or equal than the value.

func In

func In[T comparable, TT ~[]T](values TT) func(T) bool

In returns a predicate that returns true in case its argument is contained in the given slice of values.

func IsNone added in v0.4.0

func IsNone[V any](_ V, some bool) bool

IsNone returns true if the right value of the given pair of values is false. Otherwise, it returns false. This function is useful for checking if a value is absent in an optional value.

func IsNotZero added in v0.2.0

func IsNotZero[T comparable](value T) bool

IsNotZero returns true if the value is not equal to the zero value of its type.

func IsSome added in v0.4.0

func IsSome[V any](_ V, some bool) bool

IsSome returns true if the right value of the given pair of values is true. Otherwise, it returns false. This function is useful for checking if a value is present in an optional value.

func IsZero added in v0.2.0

func IsZero[T comparable](value T) bool

IsZero returns true if the value is equal to the zero value of its type.

func Less

func Less[T constraints.Ordered](value T) func(T) bool

Less returns a predicate that returns true in case its argument is less than the value.

func LessOrEqual

func LessOrEqual[T constraints.Ordered](value T) func(T) bool

LessOrEqual returns a predicate that returns true in case its argument is less or equal than the value.

func Limit

func Limit[V any, I constraints.Integer](n I, values iter.Seq[V]) iter.Seq[V]

Limit returns an iterator sequence that yields at most n values.

func Loop added in v0.4.0

func Loop[V any](seq iter.Seq[V]) iter.Seq[V]

Loop returns an iterator that yields the same sequence of values repeatedly.

func LoopSingle added in v0.4.0

func LoopSingle[V any](value V) iter.Seq[V]

LoopSingle returns an iterator that yields the same value repeatedly.

func Map

func Map[V, R any, F ~func(V) R](values iter.Seq[V], transform F) iter.Seq[R]

Map returns an iterator adapter that uses a transform function to transform values.

func MapWith added in v0.4.0

func MapWith[V, R any, F ~func(V) R](transform F) func(iter.Seq[V]) iter.Seq[R]

MapWith returns a function that transforms an iterator sequence over values to an iterator sequence over transformed values.

func Max

func Max[V constraints.Ordered](values iter.Seq[V]) (V, bool)

Max returns the maximum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false.

func MaxBy

func MaxBy[V any, K constraints.Ordered, F ~func(V) K](values iter.Seq[V], key F) (V, bool)

MaxBy returns the maximum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false. It uses the provided key function for comparison.

func MaxByCompare

func MaxByCompare[V constraints.OrderedByCompare[V]](values iter.Seq[V]) (V, bool)

MaxByCompare returns the maximum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false. It uses the Compare method for comparison.

func MaxByCompareFunc

func MaxByCompareFunc[V any, F ~func(V, V) int](values iter.Seq[V], compare F) (V, bool)

MaxByCompareFunc returns the maximum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false. It uses the provided compare function for comparison.

func MaxByLess

func MaxByLess[V constraints.OrderedByLess[V]](values iter.Seq[V]) (V, bool)

MaxByLess returns the maximum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false. It uses the Less method for comparison.

func MaxByLessFunc

func MaxByLessFunc[V any, F ~func(V, V) bool](values iter.Seq[V], less F) (V, bool)

MaxByLessFunc returns the maximum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false. It uses the provided less function for comparison.

func Min

func Min[V constraints.Ordered](values iter.Seq[V]) (V, bool)

Min returns the minimum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false.

func MinBy

func MinBy[V any, K constraints.Ordered, F ~func(V) K](values iter.Seq[V], key F) (V, bool)

MinBy returns the minimum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false. It uses the provided key function for comparison.

func MinByCompare

func MinByCompare[V constraints.OrderedByCompare[V]](values iter.Seq[V]) (V, bool)

MinByCompare returns the minimum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false. It uses the Compare method for comparison.

func MinByCompareFunc

func MinByCompareFunc[V any, F ~func(V, V) int](values iter.Seq[V], compare F) (V, bool)

MinByCompareFunc returns the minimum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false. It uses the provided compare function for comparison.

func MinByLess

func MinByLess[V constraints.OrderedByLess[V]](values iter.Seq[V]) (V, bool)

MinByLess returns the minimum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false. It uses the Less method for comparison.

func MinByLessFunc

func MinByLessFunc[V any, F ~func(V, V) bool](values iter.Seq[V], less F) (V, bool)

MinByLessFunc returns the minimum value of the given values and true if values is not empty. Otherwise, it returns the zero value of the value type and false. It uses the provided less function for comparison.

func Not

func Not[T any, P constraints.Predicate[T]](predicate P) P

Not returns a predicate that returns negated value of the given predicate.

func NotEqual

func NotEqual[T comparable](value T) func(T) bool

NotEqual returns a predicate that returns true in case its argument is not equal to the value.

func Odd

func Odd[T constraints.Integer](value T) bool

Odd returns true if the value can not be divided by 2 without a remainder.

func OneOf

func OneOf[T comparable](values ...T) func(T) bool

OneOf returns a predicate that returns true in case its argument is equal to one of the given values.

func Or

func Or[T any, P constraints.Predicate[T]](predicates ...P) P

Or returns a predicate that returns true only in case any of the given predicates return true. Or returns false if there are no given predicates.

func Product

func Product[V constraints.Number](values iter.Seq[V]) V

Product returns the product of the given values.

func Reduce

func Reduce[V any, F ~func(V, V) V](values iter.Seq[V], accumulate F) (V, bool)

Reduce reduces the values to a value which is the accumulated result of running accumulate function on each element where each successive invocation is supplied the return value of the previous one.

It returns zero value and false if the sequence is empty.

func ReduceWith added in v0.4.0

func ReduceWith[V any, F ~func(V, V) V](accumulate F) func(iter.Seq[V]) (V, bool)

ReduceWith returns a function that can be used to reduce sequences of values in a single value.

func Repeat added in v0.4.0

func Repeat[V any, I constraints.Integer](seq iter.Seq[V], n I) iter.Seq[V]

Repeat returns an iterator that yields the same sequence of values repeatedly n times.

func RepeatSingle added in v0.4.0

func RepeatSingle[V any, I constraints.Integer](value V, n I) iter.Seq[V]

RepeatSingle returns an iterator that yields the same single value repeatedly n times.

func Single added in v0.4.0

func Single[V any](value V) iter.Seq[V]

Single returns an iterator over a single value.

func Sum

func Sum[V constraints.Number](values iter.Seq[V]) V

Sum returns the sum of the given values.

func Values added in v0.4.0

func Values[V any](values ...V) iter.Seq[V]

Values returns an iterator over the given values.

Types

This section is empty.

Directories

Path Synopsis
Package constraints provides constraints for generic iterator helpers.
Package constraints provides constraints for generic iterator helpers.
Package gi2 provides a set of generic iterator combinators over pairs of values iter.Seq2.
Package gi2 provides a set of generic iterator combinators over pairs of values iter.Seq2.
Package gi2op provides a set of binary operators on pairs of values for generic iterator combinators.
Package gi2op provides a set of binary operators on pairs of values for generic iterator combinators.
Package gi2opt provides a set of generic iterator combinators over pairs of values iter.Seq adapted for optpair.Pair.
Package gi2opt provides a set of generic iterator combinators over pairs of values iter.Seq adapted for optpair.Pair.
Package giop provides a set of binary operators on scalar values for generic iterator combinators.
Package giop provides a set of binary operators on scalar values for generic iterator combinators.
Package giopt provides a set of generic iterator combinators over scalar values iter.Seq adapted for optval.Value.
Package giopt provides a set of generic iterator combinators over scalar values iter.Seq adapted for optval.Value.
internal
testing/helpers
Package helpers provides helper functions for testing.
Package helpers provides helper functions for testing.

Jump to

Keyboard shortcuts

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