gi2

package
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: 6 Imported by: 0

README

gi2 GoDoc Build Status Coverage Status

Package gi2 provides a set of helpers for working with generic iterators over pairs of values.

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And[V1, V2 any, P constraints.Predicate2[V1, V2]](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[V1, V2 any, P constraints.Predicate2[V1, V2]](predicate P) func(iter.Seq2[V1, V2]) bool

Any returns a predicate that returns true in case any of the pairs match the predicate.

func Chunk

func Chunk[V1, V2 any, I constraints.Integer](pairs iter.Seq2[V1, V2], size I) iter.Seq[iter.Seq2[V1, V2]]

Chunk returns an iterator that yields chunks of pairs of given size.

func Cloned

func Cloned[V1 constraints.Cloneable[C1], V2 constraints.Cloneable[C2], C1, C2 any](pairs iter.Seq2[V1, V2]) iter.Seq2[C1, C2]

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

func ClonedKeys

func ClonedKeys[K constraints.Cloneable[C], V, C any](pairs iter.Seq2[K, V]) iter.Seq2[C, V]

ClonedKeys is an alias for ClonedLeft that assumes the given iterator is an iterator over key/value pairs.

func ClonedLeft

func ClonedLeft[V1 constraints.Cloneable[C1], C1, V2 any](pairs iter.Seq2[V1, V2]) iter.Seq2[C1, V2]

ClonedLeft returns a new iterator that consumes original iterator and clones each first value in the pair.

func ClonedRight

func ClonedRight[V1 any, V2 constraints.Cloneable[C2], C2 any](pairs iter.Seq2[V1, V2]) iter.Seq2[V1, C2]

ClonedRight returns a new iterator that consumes original iterator and clones each second value in the pair.

func ClonedValues

func ClonedValues[K any, V constraints.Cloneable[C], C any](pairs iter.Seq2[K, V]) iter.Seq2[K, C]

ClonedValues is an alias for ClonedRight that assumes the given iterator is an iterator over key/value pairs.

func Concat

func Concat[V1, V2 any](values ...iter.Seq2[V1, V2]) iter.Seq2[V1, V2]

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

func Contains

func Contains[V1, V2 any, P constraints.Predicate2[V1, V2]](pairs iter.Seq2[V1, V2], predicate P) bool

Contains returns true if the given pairs contain a pair matching the predicate.

func ContainsKey

func ContainsKey[K comparable, V any, P constraints.Predicate[K]](pairs iter.Seq2[K, V], predicate P) bool

ContainsKey is an alias for ContainsLeft that assumes the given iterator is an iterator over key/value pairs.

func ContainsLeft

func ContainsLeft[V1 comparable, V2 any, P constraints.Predicate[V1]](pairs iter.Seq2[V1, V2], predicate P) bool

ContainsLeft returns true if the given pairs contain a pair with the first value matching the predicate.

func ContainsRight

func ContainsRight[V1 any, V2 comparable, P constraints.Predicate[V2]](pairs iter.Seq2[V1, V2], predicate P) bool

ContainsRight returns true if the given pairs contain a pair with the second value matching the predicate.

func ContainsValue

func ContainsValue[K any, V comparable, P constraints.Predicate[V]](pairs iter.Seq2[K, V], predicate P) bool

ContainsValue is an alias for ContainsRight that assumes the given iterator is an iterator over key/value pairs.

func Count

func Count[V1, V2 any](pairs iter.Seq2[V1, V2]) int

Count returns the number of pairs that match the predicate.

func Each added in v0.4.0

func Each[V1, V2 any, P constraints.Predicate2[V1, V2]](predicate P) func(iter.Seq2[V1, V2]) bool

Each returns a predicate that returns true only in case all of the pairs match the predicate.

func Empty added in v0.4.0

func Empty[V1, V2 any]() iter.Seq2[V1, V2]

Empty returns an iterator over pairs that yields nothing.

func Equal

func Equal[V1, V2 comparable](v1 V1, v2 V2) func(V1, V2) bool

Equal returns a predicate that returns true in case its arguments are equal to the values v1 and v2.

func Every

func Every[V1, V2 any, P constraints.Predicate2[V1, V2]](pairs iter.Seq2[V1, V2], predicate P) bool

Every returns true if all pairs match the predicate.

func Filter

func Filter[V1, V2 any, P constraints.Predicate2[V1, V2]](pairs iter.Seq2[V1, V2], predicate P) iter.Seq2[V1, V2]

Filter returns an iterator adapter over pairs that uses a predicate to filter them.

func FilterKeys

func FilterKeys[K, V any, P constraints.Predicate[K]](pairs iter.Seq2[K, V], predicate P) iter.Seq2[K, V]

FilterKeys is an alias for FilterLeft that assumes the given iterator is an iterator over key/value pairs.

func FilterLeft

func FilterLeft[V1, V2 any, P constraints.Predicate[V1]](pairs iter.Seq2[V1, V2], predicate P) iter.Seq2[V1, V2]

FilterLeft returns an iterator adapter over pairs that uses a predicate on the first value of a pair to filter them.

func FilterMap added in v0.4.0

func FilterMap[V1, V2, R1, R2 any, F func(V1, V2) (R1, R2, bool)](pairs iter.Seq2[V1, V2], f F) iter.Seq2[R1, R2]

FilterMap returns an iterator that yields the results of applying f to each pair of values. If f returns false for the pair, it is skipped.

func FilterMapWith added in v0.4.0

func FilterMapWith[V1, V2, R1, R2 any, F func(V1, V2) (R1, R2, bool)](f F) func(pairs iter.Seq2[V1, V2]) iter.Seq2[R1, R2]

FilterMapWith returns a function that transforms an iterator sequence over pairs to an iterator sequence over pairs. It uses the provided filter-map function to transform and filter pairs. If f returns false for the pair, it is skipped.

func FilterRight

func FilterRight[V1, V2 any, P constraints.Predicate[V2]](values iter.Seq2[V1, V2], predicate P) iter.Seq2[V1, V2]

FilterRight returns an iterator adapter over pairs that uses a predicate on the second value of a pair to filter them.

func FilterValues

func FilterValues[K, V any, P constraints.Predicate[V]](pairs iter.Seq2[K, V], predicate P) iter.Seq2[K, V]

FilterValues is an alias for FilterRight that assumes the given iterator is an iterator over key/value pairs.

func FilterWith added in v0.4.0

func FilterWith[V1, V2 any, P constraints.Predicate2[V1, V2]](predicate P) func(iter.Seq2[V1, V2]) iter.Seq2[V1, V2]

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

func Find

func Find[V1, V2 any, P constraints.Predicate2[V1, V2]](values iter.Seq2[V1, V2], predicate P) (V1, V2, bool)

Find returns the first pair among the pairs matching the predicate.

func FindWith added in v0.4.0

func FindWith[V1, V2 any, P constraints.Predicate2[V1, V2]](predicate P) func(iter.Seq2[V1, V2]) (V1, V2, bool)

FindWith returns a function that finds the first pair among the pairs matching the predicate.

func Flatten

func Flatten[V1, V2 any](values iter.Seq[iter.Seq2[V1, V2]]) iter.Seq2[V1, V2]

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

func FlattenBy

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

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

func Fold added in v0.4.0

func Fold[V1, V2, R1, R2 any, F ~func(R1, R2, V1, V2) (R1, R2)](pairs iter.Seq2[V1, V2], i1 R1, i2 R2, accumulate F) (R1, R2)

Fold reduces the sequence of pairs to a single pair using the given function.

func FoldPack added in v0.4.0

func FoldPack[V1, V2, R any, F ~func(R, V1, V2) R](pairs iter.Seq2[V1, V2], initial R, accumulate F) R

FoldPack reduces the sequence of pairs to a single value using the given function.

func FoldPackWith added in v0.4.0

func FoldPackWith[V1, V2, R any, F ~func(R, V1, V2) R](initial R, accumulate F) func(iter.Seq2[V1, V2]) R

FoldPackWith returns a function that reduces the sequence of pairs to a single value using the given function.

func FoldWith added in v0.4.0

func FoldWith[V1, V2, R1, R2 any, F ~func(R1, R2, V1, V2) (R1, R2)](i1 R1, i2 R2, accumulate F) func(iter.Seq2[V1, V2]) (R1, R2)

FoldWith returns a function that reduces the sequence of pairs to a single pair using the given function.

func Greater

func Greater[V1, V2 constraints.Ordered](o1 V1, o2 V2) func(V1, V2) bool

Greater returns a predicate that returns true in case its arguments are greater than the values v1 and v2. Values are compared in the order they are given.

func GreaterOrEqual

func GreaterOrEqual[V1, V2 constraints.Ordered](o1 V1, o2 V2) func(V1, V2) bool

GreaterOrEqual returns a predicate that returns true in case its arguments are greater or equal than the values v1 and v2. Values are compared in the order they are given.

func IsNone added in v0.4.0

func IsNone[V1, V2 any](_ V1, _ V2, some bool) bool

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

func IsNotZero

func IsNotZero[V1, V2 comparable](v1 V1, v2 V2) bool

IsNotZero returns true if any of the values is not zero.

func IsSome added in v0.4.0

func IsSome[V1, V2 any](_ V1, _ V2, some bool) bool

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

func IsZero

func IsZero[V1, V2 comparable](v1 V1, v2 V2) bool

IsZero returns true if both values are zero.

func Left added in v0.5.0

func Left[V1, V2 any](pairs iter.Seq2[V1, V2]) iter.Seq[V1]

Left returns an iterator that yields left value from each pair and discards right value.

func Less

func Less[V1, V2 constraints.Ordered](o1 V1, o2 V2) func(V1, V2) bool

Less returns a predicate that returns true in case its arguments are less than the values v1 and v2. Values are compared in the order they are given.

func LessOrEqual

func LessOrEqual[V1, V2 constraints.Ordered](o1 V1, o2 V2) func(V1, V2) bool

LessOrEqual returns a predicate that returns true in case its arguments are less or equal than the values v1 and v2. Values are compared in the order they are given.

func Limit

func Limit[V1, V2 any, I constraints.Integer](n I, pairs iter.Seq2[V1, V2]) iter.Seq2[V1, V2]

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

func Loop added in v0.4.0

func Loop[V1, V2 any](seq iter.Seq2[V1, V2]) iter.Seq2[V1, V2]

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

func LoopSingle added in v0.4.0

func LoopSingle[V1, V2 any](v1 V1, v2 V2) iter.Seq2[V1, V2]

LoopSingle returns an iterator that yields the same pair of values repeatedly.

func Map

func Map[V1, V2, R1, R2 any, F ~func(V1, V2) (R1, R2)](pairs iter.Seq2[V1, V2], transform F) iter.Seq2[R1, R2]

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

func MapKeys

func MapKeys[K, V, R any, F ~func(K) R](pairs iter.Seq2[K, V], transform F) iter.Seq2[R, V]

MapKeys is an alias for MapLeft that assumes the given iterator is an iterator over key/value pairs.

func MapLeft

func MapLeft[V1, V2, R any, F ~func(V1) R](pairs iter.Seq2[V1, V2], transform F) iter.Seq2[R, V2]

MapLeft returns an iterator adapter over pairs that uses a transform function to transform first values of pairs.

func MapRight

func MapRight[V1, V2, R any, F ~func(V2) R](pairs iter.Seq2[V1, V2], transform F) iter.Seq2[V1, R]

MapRight returns an iterator adapter over pairs that uses a transform function to transform second values of pairs.

func MapValues

func MapValues[K, V, R any, F ~func(V) R](pairs iter.Seq2[K, V], transform F) iter.Seq2[K, R]

MapValues is an alias for MapRight that assumes the given iterator is an iterator over key/value pairs.

func MapWith added in v0.4.0

func MapWith[V1, V2, R1, R2 any, F ~func(V1, V2) (R1, R2)](transform F) func(iter.Seq2[V1, V2]) iter.Seq2[R1, R2]

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

func Max

func Max[V1, V2 cmp.Ordered](values iter.Seq2[V1, V2]) (V1, V2, bool)

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

func MaxBy

func MaxBy[V1, V2 any, K cmp.Ordered, F ~func(V1, V2) K](pairs iter.Seq2[V1, V2], key F) (V1, V2, bool)

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

func MaxByLeft added in v0.4.0

func MaxByLeft[V1 cmp.Ordered, V2 any](values iter.Seq2[V1, V2]) (V1, V2, bool)

MaxByLeft returns the pair with the maximum left value and true if it is not empty. Otherwise, it returns zero values and false.

func MaxByRight added in v0.4.0

func MaxByRight[V1 any, V2 cmp.Ordered](values iter.Seq2[V1, V2]) (V1, V2, bool)

MaxByRight returns the pair with the maximum right value and true if it is not empty. Otherwise, it returns zero values and false.

func Min

func Min[V1, V2 cmp.Ordered](pairs iter.Seq2[V1, V2]) (V1, V2, bool)

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

func MinBy

func MinBy[V1, V2 any, K cmp.Ordered, F ~func(V1, V2) K](pairs iter.Seq2[V1, V2], key F) (V1, V2, bool)

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

func MinByLeft added in v0.4.0

func MinByLeft[V1 cmp.Ordered, V2 any](pairs iter.Seq2[V1, V2]) (V1, V2, bool)

MinByLeft returns the pair with the minimum left value and true if it is not empty. Otherwise, it returns zero values and false.

func MinByRight added in v0.4.0

func MinByRight[V1 any, V2 cmp.Ordered](pairs iter.Seq2[V1, V2]) (V1, V2, bool)

MinByRight returns the pair with the minimum right value and true if it is not empty. Otherwise, it returns zero values and false.

func Not

func Not[V1, V2 any, P constraints.Predicate2[V1, V2]](predicate P) P

Not returns a predicate that returns true only in case the given predicate returns false.

func NotEqual

func NotEqual[V1, V2 comparable](v1 V1, v2 V2) func(V1, V2) bool

NotEqual returns a predicate that returns true in case its arguments are not equal to the values v1 and v2.

func Or

func Or[V1, V2 any, P constraints.Predicate2[V1, V2]](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 Pack added in v0.4.0

func Pack[V1, V2, R any, F ~func(V1, V2) R](pairs iter.Seq2[V1, V2], wrap F) iter.Seq[R]

Pack returns an iterator that yields the results of applying the provided pack function to pairs.

func PackWith added in v0.4.0

func PackWith[V1, V2, R any, F ~func(V1, V2) R](pack F) func(iter.Seq2[V1, V2]) iter.Seq[R]

PackWith returns a function that transforms an iterator sequence over pairs to an iterator sequence over values. It uses the provided pack function to transform pairs to values.

func Product

func Product[V1, V2 constraints.Number](values iter.Seq2[V1, V2]) (V1, V2)

Product returns the product of the given values.

func Reduce

func Reduce[V1, V2 any, F ~func(V1, V2, V1, V2) (V1, V2)](values iter.Seq2[V1, V2], accumulate F) (V1, V2, 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.

Reduce returns [optval.None] if the sequence is empty.

func ReduceWith added in v0.4.0

func ReduceWith[V1, V2 any, F ~func(V1, V2, V1, V2) (V1, V2)](accumulate F) func(iter.Seq2[V1, V2]) (V1, V2, bool)

ReduceWith returns a function that 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.

func Repeat added in v0.4.0

func Repeat[V1, V2 any, I constraints.Integer](seq iter.Seq2[V1, V2], n I) iter.Seq2[V1, V2]

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

func RepeatSingle added in v0.4.0

func RepeatSingle[V1, V2 any, I constraints.Integer](v1 V1, v2 V2, n I) iter.Seq2[V1, V2]

RepeatSingle returns an iterator that yields the same single pair of values repeatedly n times.

func Right[V1, V2 any](pairs iter.Seq2[V1, V2]) iter.Seq[V2]

Right returns an iterator that yields right value from each pair and discards left value.

func Single added in v0.4.0

func Single[V1, V2 any](v1 V1, v2 V2) iter.Seq2[V1, V2]

Single returns an iterator over a single pair of values.

func Sum

func Sum[V1, V2 constraints.Number](pairs iter.Seq2[V1, V2]) (V1, V2)

Sum returns the sum of the given values.

func Swap added in v0.4.0

func Swap[V1, V2 any](pairs iter.Seq2[V1, V2]) iter.Seq2[V2, V1]

Swap returns an iterator that yields pairs with swapped values.

func Unpack added in v0.4.0

func Unpack[V, R1, R2 any, F ~func(V) (R1, R2)](values iter.Seq[V], unpack F) iter.Seq2[R1, R2]

Unpack returns an iterator that yields the results of applying the provided unpack function to values.

func UnpackWith added in v0.4.0

func UnpackWith[V, R1, R2 any, F ~func(V) (R1, R2)](unpack F) func(iter.Seq[V]) iter.Seq2[R1, R2]

UnpackWith returns a function that transforms an iterator sequence over values to an iterator sequence over pairs. It uses the provided unpack function to transform values to pairs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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