irt

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package irt (for IteratoRTools), provides a collection of stateless iterator handling functions, with zero dependencies on other fun packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append[T any](seq iter.Seq[T], with ...T) iter.Seq[T]

Append returns a sequence containing all elements from the input sequence followed by additional values provided.

func Apply

func Apply[T any, OP ~func(T)](seq iter.Seq[T], op OP) (count int)

Apply consumes the sequence and calls op for each element. Returns the number of elements processed.

func Apply2

func Apply2[A, B any, OP ~func(A, B)](seq iter.Seq2[A, B], op OP) (count int)

Apply2 consumes the iterator and calls op for each pair. Returns the number of pairs processed.

func ApplyAll

func ApplyAll[T any, OP ~func(T) error](seq iter.Seq[T], op OP) error

ApplyAll consumes the sequence and calls op for each element. It collects all errors returned by op and returns them joined.

func ApplyAll2

func ApplyAll2[A, B any, OP ~func(A, B) error](seq iter.Seq2[A, B], op OP) error

ApplyAll2 consumes the iterator and calls op for each pair. It collects all errors returned by op and returns them joined.

func ApplyUnless

func ApplyUnless[T any, OP ~func(T) bool](seq iter.Seq[T], op OP) int

ApplyUnless consumes the sequence and calls op for each element. Iteration stops if op returns true. Returns the number of elements processed.

func ApplyUnless2

func ApplyUnless2[A, B any, OP ~func(A, B) bool](seq iter.Seq2[A, B], op OP) int

ApplyUnless2 consumes the iterator and calls op for each pair. Iteration stops if op returns true. Returns the number of pairs processed.

func ApplyUntil

func ApplyUntil[T any, OP ~func(T) error](seq iter.Seq[T], op OP) error

ApplyUntil consumes the sequence and calls op for each element. Iteration stops if op returns an error. Returns the error from op, or nil if the sequence was fully consumed.

func ApplyUntil2

func ApplyUntil2[A, B any, OP ~func(A, B) error](seq iter.Seq2[A, B], op OP) error

ApplyUntil2 consumes the iterator and calls op for each pair. Iteration stops if op returns an error. Returns the error from op, or nil if the sequence was fully consumed.

func ApplyWhile

func ApplyWhile[T any, OP ~func(T) bool](seq iter.Seq[T], op OP) (count int)

ApplyWhile consumes the sequence and calls op for each element. Iteration stops if op returns false. Returns the number of elements processed.

func ApplyWhile2

func ApplyWhile2[A, B any, OP ~func(A, B) bool](seq iter.Seq2[A, B], op OP) (count int)

ApplyWhile2 consumes the iterator and calls op for each pair. Iteration stops if op returns false. Returns the number of pairs processed.

func Args

func Args[T any](items ...T) iter.Seq[T]

Args returns a sequence containing all provided arguments.

func AsGenerator

func AsGenerator[T any](seq iter.Seq[T]) func(context.Context) (T, bool)

AsGenerator provides in inverse of the GenerateOk operation: the function will yield values. When the boolean "ok" value is false the sequence has been exhausted.

func Chain

func Chain[T any](seq iter.Seq[iter.Seq[T]]) iter.Seq[T]

Chain flattens a sequence of sequences into a single sequence.

func Chain2

func Chain2[A, B any](seq iter.Seq[iter.Seq2[A, B]]) iter.Seq2[A, B]

Chain2 flattens a sequence of pair sequences into a single pair sequence.

func ChainMaps

func ChainMaps[A comparable, B any, M ~map[A]B](seq iter.Seq[M]) iter.Seq2[A, B]

ChainMaps flattens a sequence of maps into a single sequence.

func ChainSlices

func ChainSlices[T any, S ~[]T](seq iter.Seq[S]) iter.Seq[T]

ChainSlices flattens a sequence of slices into a single sequence.

func Channel

func Channel[T any](ctx context.Context, ch <-chan T) iter.Seq[T]

Channel returns a sequence that yields elements from the provided channel until the channel is closed or the context is canceled.

func Chunk

func Chunk[T any](seq iter.Seq[T], num int) iter.Seq[iter.Seq[T]]

Chunk returns a sequence of sequences, where each inner sequence contains at most num elements from the input sequence. If num <= 0, the sequence is empty.

func Collect

func Collect[T any](seq iter.Seq[T], args ...int) (s []T)

Collect consumes the sequence and returns a slice of all elements. This combines the operations slices.Collect and make([]T).

Unlike you can only set the capacity, not the initial length. For compatibility, you can specify more than one integer arguments, though ONLY one can be non-zero. If you specify a capacity argument that is less than zero, it becomes zero.

func Collect2

func Collect2[K comparable, V any](seq iter.Seq2[K, V], args ...int) map[K]V

Collect2 consumes the sequence and returns a map with all elements. This combines the operations maps.Collect and make(map[K]V).

Like make(map[K]V), the optional args are args[0] sets initial length.

func CollectFirstN

func CollectFirstN[T any](seq iter.Seq[T], n int) []T

CollectFirstN consumes up to n elements from the sequence and returns them as a slice. If n <= 0, returns an empty slice.

func Contains

func Contains[T comparable](seq iter.Seq[T], cmp T) (ok bool)

Contains returns true if the sequence contains an element equal to cmp. Iteration stops as soon as a match is found.

func Convert

func Convert[A, B any, OP ~func(A) B](seq iter.Seq[A], op OP) iter.Seq[B]

Convert returns a sequence where each element is the result of applying op to the elements of the input sequence.

func Convert2

func Convert2[A, B, C, D any, OP ~func(A, B) (C, D)](seq iter.Seq2[A, B], op OP) iter.Seq2[C, D]

Convert2 returns a iterator where each pair is the result of applying op to the pairs of the input iterator.

func Count

func Count[T any](seq iter.Seq[T]) (size int)

Count consumes the sequence and returns the total number of elements.

func Count2

func Count2[A, B any](seq iter.Seq2[A, B]) (size int)

Count2 consumes the iterator and returns the total number of pairs.

func Deref

func Deref[T any](seq iter.Seq[*T]) iter.Seq[T]

Deref returns a sequence of values dereferenced from the input sequence of pointers. Nil pointers in the input sequence are skipped.

func DerefWithZeros

func DerefWithZeros[T any](seq iter.Seq[*T]) iter.Seq[T]

DerefWithZeros returns a sequence of values dereferenced from the input sequence of pointers. Nil pointers in the input sequence result in the zero value for the type.

func Equal

func Equal[T comparable](rh iter.Seq[T], lh iter.Seq[T]) bool

Equal returns true if the two sequences contain the same elements in the same order.

func First

func First[A, B any](seq iter.Seq2[A, B]) iter.Seq[A]

First returns a sequence containing only the first element (key) of each pair in the input iterator.

func FirstValue

func FirstValue[T any](seq iter.Seq[T]) (zero T, ok bool)

FirstValue returns the first value from the sequence and true. If the sequence is empty, it returns the zero value and false.

func FirstValue2

func FirstValue2[A, B any](seq iter.Seq2[A, B]) (azero A, bzero B, ok bool)

FirstValue2 returns the first pair of values from the iterator and true. If the sequence is empty, it returns zero values and false.

func Flip

func Flip[A, B any](seq iter.Seq2[A, B]) iter.Seq2[B, A]

Flip returns a iterator where the keys and values of the input sequence are swapped.

func ForEach

func ForEach[T any, OP ~func(T)](seq iter.Seq[T], op OP) iter.Seq[T]

ForEach returns a sequence that calls op for each element of the input sequence during iteration.

func ForEach2

func ForEach2[A, B any, OP ~func(A, B)](seq iter.Seq2[A, B], op OP) iter.Seq2[A, B]

ForEach2 returns a iterator that calls op for each pair of the input iterator during iteration.

func ForEachWhile

func ForEachWhile[T any, OP func(T) bool](seq iter.Seq[T], op OP) iter.Seq[T]

ForEachWhile returns a sequence that calls op for each element of the input sequence. Iteration stops if op returns false.

func ForEachWhile2

func ForEachWhile2[A, B any, OP ~func(A, B) bool](seq iter.Seq2[A, B], op OP) iter.Seq2[A, B]

ForEachWhile2 returns a iterator that calls op for each pair of the input iterator. Iteration stops if op returns false.

func Generate

func Generate[T any, OP ~func() T](op OP) iter.Seq[T]

Generate returns an infinite sequence where each element is produced by calling op.

func Generate2

func Generate2[A, B any, OP ~func() (A, B)](op OP) iter.Seq2[A, B]

Generate2 returns an infinite iterator where each pair is produced by calling op.

func GenerateN

func GenerateN[T any, OP ~func() T](num int, op OP) iter.Seq[T]

GenerateN returns a sequence that yields exactly num elements produced by calling op. If num <= 0, the sequence is empty.

func GenerateOk

func GenerateOk[T any, OP ~func() (T, bool)](gen OP) iter.Seq[T]

GenerateOk returns a sequence that yields values produced by gen as long as gen returns true.

func GenerateOk2

func GenerateOk2[A, B any, OP ~func() (A, B, bool)](gen OP) iter.Seq2[A, B]

GenerateOk2 returns a iterator that yields pairs produced by gen as long as gen returns true.

func GenerateWhile

func GenerateWhile[T any, OP ~func() T, CHECK ~func(T) bool](op OP, while CHECK) iter.Seq[T]

GenerateWhile returns a sequence that yields values produced by op as long as they satisfy the while predicate.

func GenerateWhile2

func GenerateWhile2[A, B any, OP ~func() (A, B), WHILE ~func(A, B) bool](op OP, while WHILE) iter.Seq2[A, B]

GenerateWhile2 returns a iterator that yields pairs produced by op as long as they satisfy the while predicate.

func Group

func Group[K comparable, V any](seq iter.Seq2[K, V]) iter.Seq2[K, []V]

Group consumes the iterator and groups values by their keys into a iterator of keys and slices of values.

func GroupBy

func GroupBy[K comparable, V any](seq iter.Seq[V], groupBy func(V) K) iter.Seq2[K, []V]

GroupBy consumes the sequence and groups elements into a iterator of keys and slices of values, using the groupBy function to determine the key for each element.

func Index

func Index[T any](seq iter.Seq[T]) iter.Seq2[int, T]

Index returns a iterator where each element from the input sequence is paired with its 0-based index.

func Join

func Join[T any](seqs ...iter.Seq[T]) iter.Seq[T]

Join concatenates multiple sequences into a single sequence, yielding all elements from each sequence in order.

func Join2

func Join2[A, B any](seqs ...iter.Seq2[A, B]) iter.Seq2[A, B]

Join2 concatenates multiple pair sequences into a single pair sequence, yielding all key-value pairs from each sequence in order.

func JoinErrors

func JoinErrors(seq iter.Seq[error]) error

JoinErrors consumes a sequence of errors and returns a single error produced by errors.Join. Returns nil if the sequence is empty.

func KVapply

func KVapply[A, B any](seq iter.Seq[KV[A, B]], op func(A, B))

KVapply applies a function to each Elem in a sequence.

func KVargs

func KVargs[A, B any](elems ...KV[A, B]) iter.Seq2[A, B]

KVargs takes a variadic sequence of KV args and returns a pair iterator.

func KVcmp

func KVcmp[A, B cmp.Ordered](lh, rh KV[A, B]) int

KVcmp compares two Elem values by comparing both their First and Second fields.

func KVcmpFirst

func KVcmpFirst[A cmp.Ordered, B any](lh, rh KV[A, B]) int

KVcmpFirst compares two Elem values by comparing only their First fields.

func KVcmpSecond

func KVcmpSecond[A any, B cmp.Ordered](l, r KV[A, B]) int

KVcmpSecond compares two Elem values by comparing only their Second fields.

func KVjoin

func KVjoin[A, B any](seq iter.Seq2[A, B]) iter.Seq[KV[A, B]]

KVjoin converts an iter.Seq2 into an iter.Seq of Elem pairs.

func KVmap added in v0.14.1

func KVmap[A comparable, B any, M ~map[A]B](in M) iter.Seq[KV[A, B]]

KVmap converts a map into a sequence of KV pairs, and returns them as an iterator.

func KVsplit

func KVsplit[A, B any](seq iter.Seq[KV[A, B]]) iter.Seq2[A, B]

KVsplit converts an iter.Seq of Elem pairs into an iter.Seq2.

func Keep

func Keep[T any](seq iter.Seq[T], prd func(T) bool) iter.Seq[T]

Keep returns a sequence containing only the elements from the input sequence that satisfy the predicate prd.

func Keep2

func Keep2[A, B any](seq iter.Seq2[A, B], prd func(A, B) bool) iter.Seq2[A, B]

Keep2 returns a iterator containing only the pairs from the input iterator that satisfy the predicate prd.

func KeepErrors

func KeepErrors(seq iter.Seq[error]) iter.Seq[error]

KeepErrors returns a sequence containing only the non-nil errors from the input sequence.

func KeepOk

func KeepOk[T any](seq iter.Seq2[T, bool]) iter.Seq[T]

KeepOk returns a sequence containing only the values from pairs where the boolean is true.

func Limit

func Limit[T any](seq iter.Seq[T], n int) iter.Seq[T]

Limit returns a sequence that yields at most n elements from the input sequence. If n <= 0, the sequence is empty.

func Limit2

func Limit2[A, B any](seq iter.Seq2[A, B], n int) iter.Seq2[A, B]

Limit2 returns a iterator that yields at most n pairs from the input iterator. If n <= 0, the sequence is empty.

func Map

func Map[K comparable, V any, M ~map[K]V](mp M) iter.Seq2[K, V]

Map returns a iterator containing all key-value pairs from the map.

func MapKV added in v0.14.1

func MapKV[A comparable, B any, M ~map[A]B](mp M) iter.Seq[KV[A, B]]

MapKV transforms a map into an iterator of KV pairs.

func Merge

func Merge[A, B, C any, OP ~func(A, B) C](seq iter.Seq2[A, B], op OP) iter.Seq[C]

Merge returns a sequence where each element is the result of applying op to the pairs of the input iterator.

func Modify

func Modify[T any, OP ~func(T) T](seq iter.Seq[T], op OP) iter.Seq[T]

Modify applies a transformation function to each element in the sequence. If the operation is nil, the sequence is returned unchanged.

func Modify2

func Modify2[A, B any, OP ~func(A, B) (A, B)](seq iter.Seq2[A, B], op OP) iter.Seq2[A, B]

Modify2 applies a transformation function to each pair in the sequence. If the operation is nil, the sequence is returned unchanged.

func ModifyAll

func ModifyAll[T any, OP ~func(T) T](seq iter.Seq[T], ops ...OP) iter.Seq[T]

ModifyAll applies a sequence of transformation functions to each element in the sequence. Nil modification functions are skipped. Each transformation is applied in order, with the result of one transformation passed to the next.

func ModifyAll2

func ModifyAll2[A, B any](seq iter.Seq2[A, B], ops ...func(A, B) (A, B)) iter.Seq2[A, B]

ModifyAll2 applies a sequence of transformation functions to each pair in the sequence. Nil functions are filtered out and skipped. Each transformation is applied in order, with the result of one transformation passed to the next.

func Monotonic

func Monotonic() iter.Seq[int]

Monotonic returns an infinite sequence of integers starting from 1.

func MonotonicFrom

func MonotonicFrom(start int) iter.Seq[int]

MonotonicFrom returns an infinite sequence of integers starting from start.

func One

func One[T any](v T) iter.Seq[T]

One returns a sequence containing exactly one element.

func Pipe

func Pipe[T any](ctx context.Context, seq iter.Seq[T]) <-chan T

Pipe returns a channel that receives all elements from the input sequence. The channel is closed when the sequence is exhausted or the context is canceled.

func Ptrs

func Ptrs[T any](seq iter.Seq[T]) iter.Seq[*T]

Ptrs returns a sequence where each element is a pointer to the value in the input sequence.

func PtrsWithNils

func PtrsWithNils[T comparable](seq iter.Seq[T]) iter.Seq[*T]

PtrsWithNils returns a sequence of pointers to the values in the input sequence. If a value is the zero value for its type, a nil pointer is produced instead.

func Range

func Range(start int, end int) iter.Seq[int]

Range returns a sequence of integers from start to end (inclusive).

func ReadLines

func ReadLines(reader io.Reader) iter.Seq[string]

ReadLines returns a sequence of strings from the reader, stopping at the first error.

func ReadLinesErr

func ReadLinesErr(reader io.Reader) iter.Seq2[string, error]

ReadLinesErr returns a iterator of strings and errors from the reader. It yields each line with a nil error, and finally yields an empty string and the scanner's error.

func Reduce

func Reduce[A, B any](seq iter.Seq[A], rfn func(B, A) B) (out B)

Reduce consumes the sequence and reduces it to a single value by repeatedly applying rfn.

func Reduce2 added in v0.14.1

func Reduce2[A, B, C any](seq iter.Seq2[A, B], rfn func(C, A, B) C) (out C)

Reduce2 consumes a sequence o pairs and reduces it to a single value by repeatedly applying rfn.

func Remove

func Remove[T any](seq iter.Seq[T], prd func(T) bool) iter.Seq[T]

Remove returns a sequence containing only the elements from the input sequence that do NOT satisfy the predicate prd.

func Remove2

func Remove2[A, B any](seq iter.Seq2[A, B], prd func(A, B) bool) iter.Seq2[A, B]

Remove2 returns a iterator containing only the pairs from the input iterator that do NOT satisfy the predicate prd.

func RemoveErrors

func RemoveErrors[T any](seq iter.Seq2[T, error]) iter.Seq[T]

RemoveErrors returns a sequence containing only the values from pairs where the error is nil.

func RemoveNils

func RemoveNils[T any](seq iter.Seq[*T]) iter.Seq[*T]

RemoveNils returns a sequence containing all non-nil pointers from the input sequence.

func RemoveZeros

func RemoveZeros[T comparable](seq iter.Seq[T]) iter.Seq[T]

RemoveZeros returns a sequence containing all non-zero values from the input sequence.

func Resolve added in v0.14.2

func Resolve[T any, F ~func() T](seq iter.Seq[F]) iter.Seq[T]

Resolve returns a sequence that lazily executes each function in the input sequence and yields the results. Functions are only called during iteration.

func Resolve2 added in v0.14.2

func Resolve2[A, B any, F ~func() (A, B)](seq iter.Seq[F]) iter.Seq2[A, B]

Resolve2 returns a pair sequence that lazily executes each function in the input sequence and yields the result pairs. Functions are only called during iteration.

func ResolveWrap added in v0.14.2

func ResolveWrap[A, B any, F ~func(A) B](seq iter.Seq[F], wrapping A) iter.Seq[B]

ResolveWrap returns a sequence that lazily executes each function in the input sequence with the provided argument and yields the results. Functions are only called during iteration.

func ResolveWrap2 added in v0.14.2

func ResolveWrap2[A, B, C any, F ~func(A) (B, C)](seq iter.Seq[F], wrapping A) iter.Seq2[B, C]

ResolveWrap2 returns a pair sequence that lazily executes each function in the input sequence with the provided argument and yields the result pairs. Functions are only called during iteration.

func RunAll

func RunAll[OP ~func()](seq iter.Seq[OP]) (count int)

RunAll takes a sequences of nilary functions and runs them all, returning a count. If any functions are Nil. For other function types, and for nil/panic safety, use the operations in the wpa package.

func Second

func Second[A, B any](seq iter.Seq2[A, B]) iter.Seq[B]

Second returns a sequence containing only the second element (value) of each pair in the input iterator.

func Shard

func Shard[T any](ctx context.Context, num int, seq iter.Seq[T]) iter.Seq[iter.Seq[T]]

Shard splits the input sequence into num separate sequences. Elements are distributed.

func Slice

func Slice[T any, S ~[]T](sl S) iter.Seq[T]

Slice returns a sequence containing all elements from the slice.

func SortBy

func SortBy[K cmp.Ordered, T any](seq iter.Seq[T], cf func(T) K) iter.Seq[T]

SortBy consumes the sequence, sorts it based on the keys produced by cf, and returns a new sequence of the sorted elements.

func SortBy2

func SortBy2[K cmp.Ordered, A, B any](seq iter.Seq2[A, B], cf func(A, B) K) iter.Seq2[A, B]

SortBy2 consumes the iterator, sorts it based on the keys produced by cf, and returns a new iterator of the sorted pairs.

func Two

func Two[A, B any](a A, b B) iter.Seq2[A, B]

Two returns a iterator containing exactly one pair of elements.

func Unique

func Unique[T comparable](seq iter.Seq[T]) iter.Seq[T]

Unique returns a sequence containing only the first occurrence of each unique element from the input sequence.

func UniqueBy

func UniqueBy[K comparable, V any](seq iter.Seq[V], kfn func(V) K) iter.Seq[V]

UniqueBy returns a sequence containing only the first occurrence of each element from the input sequence that produces a unique key when passed to kfn.

func Until

func Until[T any](seq iter.Seq[T], prd func(T) bool) iter.Seq[T]

Until returns a sequence that yields elements from the input sequence until the predicate prd returns true.

func Until2

func Until2[A, B any](seq iter.Seq2[A, B], is func(A, B) bool) iter.Seq2[A, B]

Until2 returns a iterator that yields pairs from the input iterator until the predicate is returns true.

func UntilError

func UntilError[T any](seq iter.Seq2[T, error]) iter.Seq[T]

UntilError returns a sequence of values from pairs, stopping when a non-nil error is encountered.

func UntilNil

func UntilNil[T any](seq iter.Seq[*T]) iter.Seq[T]

UntilNil returns a sequence of dereferenced values from the input sequence of pointers, stopping when a nil pointer is encountered.

func While

func While[T any](seq iter.Seq[T], prd func(T) bool) iter.Seq[T]

While returns a sequence that yields elements from the input sequence as long as the predicate prd returns true.

func While2

func While2[A, B any](seq iter.Seq2[A, B], prd func(A, B) bool) iter.Seq2[A, B]

While2 returns a iterator that yields pairs from the input iterator as long as the predicate prd returns true.

func WhileOk

func WhileOk[T any](seq iter.Seq2[T, bool]) iter.Seq[T]

WhileOk returns a sequence that yields values from pairs as long as the boolean is true.

func WhileSuccess

func WhileSuccess[T any](seq iter.Seq2[T, error]) iter.Seq[T]

WhileSuccess returns a sequence that yields values from pairs as long as the error is nil.

func With

func With[A, B any, OP ~func(A) B](seq iter.Seq[A], op OP) iter.Seq2[A, B]

With returns a iterator where each element from the input sequence is paired with the result of applying op to it.

func With2

func With2[A, B, C any, OP ~func(A) (B, C)](seq iter.Seq[A], op OP) iter.Seq2[B, C]

With2 returns a iterator where each pair is produced by applying op to each element of the input sequence.

func With3

func With3[A, B, C any, OP ~func(A) (B, C)](seq iter.Seq[A], op OP) iter.Seq2[KV[A, B], C]

With3 returns a iterator where each pair is produced by applying op to each element of the input sequence.

func WithBuffer

func WithBuffer[T any](ctx context.Context, seq iter.Seq[T], size int) iter.Seq[T]

WithBuffer maintains a buffer of items read from the source iterator, waiting for downstream consumers of the output iterator, to consume them.

func WithEach

func WithEach[A, B any, OP ~func() B](seq iter.Seq[A], op OP) iter.Seq2[A, B]

WithEach returns a iterator where each element from the input sequence is paired with a value produced by calling op.

func WithHooks

func WithHooks[T any](seq iter.Seq[T], before func(), after func()) iter.Seq[T]

WithHooks returns a sequence that calls before() when iteration starts and after() when iteration ends. after() is called even if iteration stops early. Nil hooks are ignored.

func WithMutex

func WithMutex[T any](seq iter.Seq[T], mtx *sync.Mutex) iter.Seq[T]

WithMutex returns a sequence that synchronizes all calls to the underlying iterator using the provided mutex.

func WithMutex2

func WithMutex2[A, B any](seq iter.Seq2[A, B], mtx *sync.Mutex) iter.Seq2[A, B]

WithMutex2 returns a pair sequence that synchronizes all calls to the underlying iterator using the provided mutex.

func WithSetup

func WithSetup[T any](seq iter.Seq[T], setup func()) iter.Seq[T]

WithSetup returns a sequence that calls setup() exactly once when iteration starts for the first time.

func Zip

func Zip[A, B any](rh iter.Seq[A], lh iter.Seq[B]) iter.Seq2[A, B]

Zip returns a iterator that pairs elements from rh and lh. Iteration stops when either sequence is exhausted.

Types

type KV

type KV[A, B any] struct {
	Key   A
	Value B
}

KV is a generic pair type that holds two values of potentially different types.

func MakeKV

func MakeKV[A, B any](a A, b B) KV[A, B]

MakeKV creates a KV from two values.

func WithKV

func WithKV[A, B any](a A, with func(A) B) KV[A, B]

WithKV creates a KV by applying a function to the first value to derive the second value.

func (KV[A, B]) Apply

func (e KV[A, B]) Apply(op func(A, B))

Apply calls the provided function with the First and Second values of the Elem.

func (KV[A, B]) Compare

func (e KV[A, B]) Compare(aop func(A, A) int, bop func(B, B) int) interface{ With(KV[A, B]) int }

Compare returns a comparator that compares both First and Second fields using the provided comparison functions.

func (KV[A, B]) CompareFirst

func (e KV[A, B]) CompareFirst(aop func(A, A) int) interface{ With(KV[A, B]) int }

CompareFirst returns a comparator that compares only the First field using the provided comparison function.

func (KV[A, B]) CompareSecond

func (e KV[A, B]) CompareSecond(bop func(B, B) int) interface{ With(KV[A, B]) int }

CompareSecond returns a comparator that compares only the Second field using the provided comparison function.

func (KV[A, B]) Split

func (e KV[A, B]) Split() (A, B)

Split returns the First and Second values of an Elem as separate return values.

Jump to

Keyboard shortcuts

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