collection

package module
v1.171.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

Package collection provides utilities for working with slices, maps, and sequences.

The package mixes eager helpers for slices with lazy helpers built on top of `iter.Seq`, so the same collection-oriented operations can be applied to both in-memory data and streamed values.

The overall style is primarily driven by the Go standard library and the needs of this repository, with some influence from helper libraries such as:

Where possible, helpers should complement rather than duplicate what is already available in the standard `slices` package.

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

Package collection provides various utilities working on slices or sequences

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(slice []bool) bool

All returns true if all items of the slice are true.

func AllFunc

func AllFunc[S ~[]E, E any](s S, f Predicate[E]) bool

AllFunc returns true if f returns true for every element in s.

func AllNotEmpty

func AllNotEmpty(strict bool, slice []string) bool

AllNotEmpty returns true when every entry of slice is non-empty. If strict is true, strings containing only whitespace are considered empty.

func AllSequence

func AllSequence(seq iter.Seq[bool]) bool

AllSequence returns true if all items of the sequence are true.

func AllTrue

func AllTrue(values ...bool) bool

AllTrue returns whether all values are true.

func AllTrueSequence

func AllTrueSequence[E any](s iter.Seq[E], f Predicate[E]) bool

AllTrueSequence returns true if f returns true for every element in the sequence.

func And

func And(values ...bool) bool

And performs an 'and' operation on an array of booleans.

func Any

func Any(slice []bool) bool

Any returns true if there is at least one element of the slice which is true.

func AnyEmpty

func AnyEmpty(strict bool, slice []string) bool

AnyEmpty returns true if any entry of slice is empty. If strict is true, strings containing only whitespace are considered empty.

func AnyFalse

func AnyFalse(values ...bool) bool

AnyFalse returns whether there is a value set to false

func AnyFalseSequence

func AnyFalseSequence(eq iter.Seq[bool]) bool

AnyFalseSequence returns true if there is at least one element of the sequence which is false. If the sequence is empty, it also returns true.

func AnyFunc

func AnyFunc[S ~[]E, E any](s S, f Predicate[E]) bool

AnyFunc returns true if at least one element in s satisfies f.

func AnyRefFunc

func AnyRefFunc[S ~[]E, E any](s S, f PredicateRef[E]) bool

AnyRefFunc behaves like AnyFunc but accepts a reference-based predicate.

func AnySequence

func AnySequence(seq iter.Seq[bool]) bool

AnySequence returns true if there is at least one element of the slice which is true.

func AnyTrue

func AnyTrue(values ...bool) bool

AnyTrue returns whether there is a value set to true

func At

func At[S ~[]E, E any](slice S, index int) (element E, ok bool)

At returns the element at index from slice.

Negative indices are interpreted relative to the end of the slice, following the same pattern as Python indexing, so `-1` selects the last element, `-2` the penultimate one, and so on.

If index is out of range, it returns the zero value and false.

References:

func AtSequence

func AtSequence[E any](seq iter.Seq[E], index int) (element E, ok bool)

AtSequence returns the element at index from seq.

Negative indices are interpreted relative to the end of the sequence, following the same pattern as Python indexing.

If index is out of range, it returns the zero value and false.

References:

func Coalesce

func Coalesce[T any](items []T, merge MergeFunc[T]) []T

Coalesce compacts items by merging adjacent compatible elements.

Items are processed from left to right. Each new item is only considered for merging with the last item already emitted in the output. If merge returns ok=true, the last output item is replaced with the merged value; otherwise the item is appended as a new output element.

This is similar to Rust itertools::coalesce and is useful when neighbouring values may collapse into a more compact representation.

References:

func CoalesceRef

func CoalesceRef[T any](items []T, merge MergeRefFunc[T]) []T

CoalesceRef compacts items by merging adjacent compatible elements using a reference-based merge function.

func ConvertListOfPairsToMap

func ConvertListOfPairsToMap(input []string, pairSeparator string) (pairs map[string]string, err error)

func ConvertListOfPairsToMapWithOptions

func ConvertListOfPairsToMapWithOptions(input []string, opts ...PairOption) (pairs map[string]string, err error)

func ConvertMapToCommaSeparatedList

func ConvertMapToCommaSeparatedList[K comparable, V any](pairs map[K]V) string

ConvertMapToCommaSeparatedList converts a map to a string of comma separated list of keys and values defined sequentially

func ConvertMapToCommaSeparatedPairsList

func ConvertMapToCommaSeparatedPairsList[K comparable, V any](pairs map[K]V, pairSeparator string) string

ConvertMapToCommaSeparatedPairsList converts a map to a string of comma separated list of key, value pairs.

func ConvertMapToLoggerValues

func ConvertMapToLoggerValues[K comparable, V any](pairs map[K]V) []any

ConvertMapToLoggerValues is similar to ConvertMapToSlice but returns a type compatible with logr.Logger.

func ConvertMapToOrderedCommaSeparatedList

func ConvertMapToOrderedCommaSeparatedList[K cmp.Ordered, V any](pairs map[K]V) string

ConvertMapToOrderedCommaSeparatedList converts a map to a commar-separated list and ensures that the ordering will always be the same

func ConvertMapToOrderedSlice

func ConvertMapToOrderedSlice[K cmp.Ordered, V any](pairs map[K]V) []string

ConvertMapToOrderedSlice converts a map to a slice and ensures that the ordering will always be the same

func ConvertMapToPairSlice

func ConvertMapToPairSlice[K comparable, V any](pairs map[K]V, pairSeparator string) []string

ConvertMapToPairSlice converts a map to list of key value pairs e.g. ["key1=value1", "key2=value2"]

func ConvertMapToSlice

func ConvertMapToSlice[K comparable, V any](pairs map[K]V) []string

ConvertMapToSlice converts a map to list of keys and values listed sequentially e.g. [key1, value1, key2, value2]

func ConvertSliceToCommaSeparatedList

func ConvertSliceToCommaSeparatedList[T any](slice []T) string

ConvertSliceToCommaSeparatedList converts a slice into a string containing a coma separated list

func ConvertSliceToMap

func ConvertSliceToMap[T comparable](input []T) (pairs map[T]T, err error)

ConvertSliceToMap converts a slice of elements into a map e.g. [key1, value1, key2, values2] -> {key1: value1, key2: value2}

func CountBy

func CountBy[S ~[]E, E any](slice S, predicate Predicate[E]) int

CountBy counts how many elements in a slice satisfy the predicate.

This is useful when a collection should be reduced to the number of matching elements, for example, counting even values, enabled items, or values that match a threshold.

Reference documentation:

func CountByRef

func CountByRef[S ~[]E, E any](slice S, predicate PredicateRef[E]) int

CountByRef behaves like CountBy but accepts a reference-based predicate.

func CountByRefSequence

func CountByRefSequence[E any](sequence iter.Seq[E], predicate PredicateRef[E]) int

CountByRefSequence behaves like CountBySequence but accepts a reference-based predicate.

func CountBySequence

func CountBySequence[E any](sequence iter.Seq[E], predicate Predicate[E]) int

CountBySequence counts how many elements in a sequence satisfy predicate.

This is useful when values are processed lazily through iterators rather than from a prebuilt slice.

func Difference

func Difference[T comparable](slice1, slice2 []T) []T

Difference returns distinct values present in slice1 but not in slice2.

func Drop

func Drop[S ~[]E, E any](slice S, count int) S

Drop returns slice without its first count elements.

func DropSequence

func DropSequence[E any](seq iter.Seq[E], count int) iter.Seq[E]

DropSequence skips the first count elements of seq.

func DropWhile

func DropWhile[S ~[]E, E any](slice S, predicate Predicate[E]) S

DropWhile returns slice without its leading elements that satisfy predicate.

func DropWhileSequence

func DropWhileSequence[E any](seq iter.Seq[E], predicate Predicate[E]) iter.Seq[E]

DropWhileSequence skips the leading elements of seq that satisfy predicate.

func Each

func Each[T any](s iter.Seq[T], f OperationFunc[T]) error

Each iterates over a sequence and invokes f for each element. If f returns a non-EOF error, iteration stops and that error is returned. If f returns EOF, the EOF is ignored and iteration ends without error.

func EachRef

func EachRef[T any](s iter.Seq[T], f OperationRefFunc[T]) error

EachRef behaves like Each but invokes f with a reference to each element.

func EachSlice

func EachSlice[S ~[]E, E any](s S, f OperationFunc[E]) error

EachSlice iterates over a slice and invokes f for each element. If f returns a non-EOF error, iteration stops and that error is returned. If f returns EOF, the EOF is ignored and iteration ends without error.

func EachSliceRef

func EachSliceRef[S ~[]E, E any](s S, f OperationRefFunc[E]) error

EachSliceRef behaves like EachSlice but invokes f with a reference to each element.

func EmptySequence

func EmptySequence[T any]() iter.Seq[T]

EmptySequence returns a sequence that yields no values.

This is useful when APIs need to return an `iter.Seq` but have nothing to produce, or when a nil sequence should be normalised to a safe empty value so callers can range over it without panicking.

func EmptySequence2

func EmptySequence2[K any, V any]() iter.Seq2[K, V]

EmptySequence2 returns a key/value sequence that yields no pairs.

This is useful when APIs need to return an `iter.Seq2` but have nothing to produce, or when a nil key/value sequence should be normalised to a safe empty value so callers can range over it without panicking.

func Enumerate

func Enumerate[S ~[]E, E any](slice S) iter.Seq2[int, E]

Enumerate yields pairs of index and value for slice.

func EnumerateSequence

func EnumerateSequence[E any](seq iter.Seq[E]) iter.Seq2[int, E]

EnumerateSequence yields pairs of index and value for seq.

func Filter

func Filter[S ~[]E, E any](s S, f FilterFunc[E]) S

Filter returns a new slice containing elements from s for which f returns true.

This is useful when a collection should be narrowed down to only the items of interest, for example active users, matching paths, or values that pass a validation predicate.

Reference documentation:

func FilterRef

func FilterRef[S ~[]E, E any](s S, f FilterRefFunc[E]) S

FilterRef behaves like Filter but accepts a reference-based predicate.

This is useful when the predicate naturally works on pointers or when it is shared with other APIs that already use PredicateRef.

func FilterRefSequence

func FilterRefSequence[E any](s iter.Seq[E], f PredicateRef[E]) (result iter.Seq[E])

FilterRefSequence behaves like FilterSequence but accepts a reference-based predicate.

This is useful when sequence processing should remain lazy while the predicate logic is written against PredicateRef.

func FilterSequence

func FilterSequence[E any](s iter.Seq[E], f Predicate[E]) (result iter.Seq[E])

FilterSequence returns a sequence that yields only elements for which f returns true.

This is the lazy sequence-oriented counterpart to Filter and is useful when composing iterator pipelines, avoiding intermediate slices, or processing potentially large or streaming inputs incrementally.

Reference documentation:

func Find

func Find(slice *[]string, val string) (int, bool)

Find searches for val in the slice pointed to by slice. It returns the index of the first match and true when found. If slice is nil or val is not present, it returns -1 and false.

func FindInSequence

func FindInSequence[E any](elements iter.Seq[E], predicate Predicate[E]) (int, bool)

FindInSequence searches elements (a sequence) for the first item that satisfies the predicate. It returns the zero-based index of the matching element and true when a match is found. If elements is nil or no match exists, it returns -1 and false.

func FindInSequenceRef

func FindInSequenceRef[E any](elements iter.Seq[E], predicate PredicateRef[E]) (int, bool)

FindInSequenceRef behaves like FindInSequence but accepts a predicate that operates on element references.

func FindInSlice

func FindInSlice(strict bool, slice []string, val ...string) (int, bool)

FindInSlice checks whether any of the provided val arguments exist in slice. It returns the index of the first match and true if found. When strict is true, matching uses exact string equality. When strict is false, matching is case-insensitive and ignores surrounding whitespace.

If no values are provided or the slice is empty, the function returns -1 and false.

func First

func First[S ~[]E, E any](slice S) (element E, ok bool)

First returns the first element of slice.

func FirstBy

func FirstBy[S ~[]E, E any](slice S, predicate Predicate[E]) (element E, ok bool)

FirstBy returns the first element of slice that satisfies predicate.

func FirstByRef

func FirstByRef[S ~[]E, E any](slice S, predicate PredicateRef[E]) (element E, ok bool)

FirstByRef returns the first element of slice that satisfies a reference-based predicate.

func FirstByRefSequence

func FirstByRefSequence[E any](seq iter.Seq[E], predicate PredicateRef[E]) (element E, ok bool)

FirstByRefSequence returns the first element yielded by seq that satisfies a reference-based predicate.

func FirstBySequence

func FirstBySequence[E any](seq iter.Seq[E], predicate Predicate[E]) (element E, ok bool)

FirstBySequence returns the first element yielded by seq that satisfies predicate.

func FirstRef

func FirstRef[S ~[]E, E any](slice S, predicate PredicateRef[E]) (element E, ok bool)

FirstRef behaves like FirstByRef.

func FirstRefSequence

func FirstRefSequence[E any](seq iter.Seq[E], predicate PredicateRef[E]) (element E, ok bool)

FirstRefSequence behaves like FirstByRefSequence.

func FirstSequence

func FirstSequence[E any](seq iter.Seq[E]) (element E, ok bool)

FirstSequence returns the first element yielded by seq.

func FlatMap

func FlatMap[S ~[]E, E any, T any](slice S, mapper MapFunc[E, []T]) []T

FlatMap maps each element and concatenates the returned slices.

This is useful when each input element expands into zero or more output elements, such as splitting strings, flattening nested values, or projecting structs into multiple derived values.

Reference documentation:

func FlatMapRef

func FlatMapRef[S ~[]E, E any, T any](slice S, mapper MapRefFunc[E, []T]) []T

FlatMapRef behaves like FlatMap but accepts a reference-based mapper.

func FlatMapRefSequence

func FlatMapRefSequence[E any, T any](sequence iter.Seq[E], mapper MapRefFunc[E, []T]) []T

FlatMapRefSequence behaves like FlatMapSequence but accepts a reference-based mapper.

func FlatMapSequence

func FlatMapSequence[E any, T any](sequence iter.Seq[E], mapper MapFunc[E, []T]) []T

FlatMapSequence maps each sequence element and concatenates the returned slices.

func ForAll

func ForAll[S ~[]E, E any](s S, f OperationFunc[E]) error

ForAll invokes f on every element of the provided slice. Any non-EOF errors returned by f are collected and aggregated into a single error returned to the caller. If f returns EOF, iteration stops immediately.

func ForAllRef

func ForAllRef[S ~[]E, E any](s S, f OperationRefFunc[E]) error

ForAllRef behaves like ForAll but applies f to references of elements.

func ForAllSequence

func ForAllSequence[T any](s iter.Seq[T], f OperationFunc[T]) error

ForAllSequence invokes f for every element of s (a sequence). Non-EOF errors are wrapped and aggregated; EOF causes immediate termination.

func ForAllSequenceRef

func ForAllSequenceRef[T any](s iter.Seq[T], f OperationRefFunc[T]) error

ForAllSequenceRef behaves like ForAllSequence but adapts a reference-based operation.

func ForEach

func ForEach[S ~[]E, E any](s S, f OperationWithoutErrorFunc[E])

ForEach invokes f on every element of the provided slice. Any error returned by f is ignored.

func ForEachRef

func ForEachRef[S ~[]E, E any](s S, f OperationWithoutErrorRefFunc[E])

ForEachRef invokes f on every element of the provided slice, passing a reference.

func ForEachValues

func ForEachValues[E any](f func(E), values ...E)

ForEachValues invokes f for each value passed in values.

func FrequenciesBy

func FrequenciesBy[S ~[]E, E any, K comparable](slice S, keyFunc KeyFunc[E, K]) map[K]int

FrequenciesBy counts how often each derived key occurs in slice.

This is useful for building histograms or frequency tables, for example counting values by lowercase normalisation, status, or category.

Reference documentation:

func FrequenciesByRef

func FrequenciesByRef[S ~[]E, E any, K comparable](slice S, keyFunc KeyRefFunc[E, K]) map[K]int

FrequenciesByRef behaves like FrequenciesBy but accepts a reference-based key function.

func FrequenciesByRefSequence

func FrequenciesByRefSequence[E any, K comparable](sequence iter.Seq[E], keyFunc KeyRefFunc[E, K]) map[K]int

FrequenciesByRefSequence behaves like FrequenciesBySequence but accepts a reference-based key function.

func FrequenciesBySequence

func FrequenciesBySequence[E any, K comparable](sequence iter.Seq[E], keyFunc KeyFunc[E, K]) map[K]int

FrequenciesBySequence counts how often each derived key occurs in a sequence.

func GenericRemove

func GenericRemove(equal func(string, string) bool, slice []string, val ...string) []string

GenericRemove looks for elements in a slice using the equal function. If they're found, it will remove them from the slice.

func GroupBy

func GroupBy[S ~[]E, E any, K comparable](slice S, keyFunc KeyFunc[E, K]) map[K][]E

GroupBy groups slice elements by the key returned by keyFunc.

This is useful when a collection should be partitioned into buckets, such as grouping users by role, strings by length, or values by status.

Reference documentation:

func GroupByRef

func GroupByRef[S ~[]E, E any, K comparable](slice S, keyFunc KeyRefFunc[E, K]) map[K][]E

GroupByRef behaves like GroupBy but accepts a reference-based key function.

func GroupByRefSequence

func GroupByRefSequence[E any, K comparable](sequence iter.Seq[E], keyFunc KeyRefFunc[E, K]) map[K][]E

GroupByRefSequence behaves like GroupBySequence but accepts a reference-based key function.

func GroupBySequence

func GroupBySequence[E any, K comparable](sequence iter.Seq[E], keyFunc KeyFunc[E, K]) map[K][]E

GroupBySequence groups sequence elements by the key returned by keyFunc.

This is useful when grouping should happen during lazy iteration rather than after collecting values into a slice.

func In

func In[Slice ~[]E, E any](s Slice, v E, m ...MatchFunc[E]) bool

In reports whether any element in s matches v using any of the provided match functions. Match functions that return an error are treated as non-matches.

func InRef

func InRef[Slice ~[]E, E any](s Slice, v *E, m ...MatchRefFunc[E]) bool

InRef behaves like In but uses reference-based match functions and a reference value.

func InSequence

func InSequence[E any](s iter.Seq[E], v E, m ...MatchFunc[E]) bool

InSequence reports whether any element in s matches v using any of the provided match functions. Match functions that return an error are treated as non-matches.

func InSequenceRef

func InSequenceRef[E any](s iter.Seq[E], v *E, m ...MatchRefFunc[E]) bool

InSequenceRef behaves like InSequence but uses reference-based match functions and a reference value.

func IndexBy

func IndexBy[S ~[]E, E any, K comparable](slice S, keyFunc KeyFunc[E, K]) map[K]E

IndexBy builds a map from derived key to value.

If multiple elements produce the same key, the last one wins.

func IndexByRef

func IndexByRef[S ~[]E, E any, K comparable](slice S, keyFunc KeyRefFunc[E, K]) map[K]E

IndexByRef behaves like IndexBy but accepts a reference-based key function.

func IndexByRefSequence

func IndexByRefSequence[E any, K comparable](sequence iter.Seq[E], keyFunc KeyRefFunc[E, K]) map[K]E

IndexByRefSequence behaves like IndexBySequence but accepts a reference-based key function.

func IndexBySequence

func IndexBySequence[E any, K comparable](sequence iter.Seq[E], keyFunc KeyFunc[E, K]) map[K]E

IndexBySequence builds a map from derived key to value from a sequence.

If multiple elements produce the same key, the last one wins.

func Intersection

func Intersection[T comparable](slice1, slice2 []T) []T

Intersection returns the distinct values common to slice1 and slice2. The order of elements is not guaranteed.

func Last

func Last[S ~[]E, E any](slice S) (element E, ok bool)

Last returns the last element of slice.

func LastBy

func LastBy[S ~[]E, E any](slice S, predicate Predicate[E]) (element E, ok bool)

LastBy returns the last element of slice that satisfies predicate.

func LastByRef

func LastByRef[S ~[]E, E any](slice S, predicate PredicateRef[E]) (element E, ok bool)

LastByRef returns the last element of slice that satisfies a reference-based predicate.

func LastByRefSequence

func LastByRefSequence[E any](seq iter.Seq[E], predicate PredicateRef[E]) (element E, ok bool)

LastByRefSequence returns the last element yielded by seq that satisfies a reference-based predicate.

func LastBySequence

func LastBySequence[E any](seq iter.Seq[E], predicate Predicate[E]) (element E, ok bool)

LastBySequence returns the last element yielded by seq that satisfies predicate.

func LastRef

func LastRef[S ~[]E, E any](slice S, predicate PredicateRef[E]) (element E, ok bool)

LastRef behaves like LastByRef.

func LastRefSequence

func LastRefSequence[E any](seq iter.Seq[E], predicate PredicateRef[E]) (element E, ok bool)

LastRefSequence behaves like LastByRefSequence.

func LastSequence

func LastSequence[E any](seq iter.Seq[E]) (element E, ok bool)

LastSequence returns the last element yielded by seq.

func Map

func Map[T1 any, T2 any](s []T1, f MapFunc[T1, T2]) []T2

Map applies f to each element of s and returns a slice with the results.

This is useful for eagerly transforming one slice into another, for example converting IDs to strings, extracting names from structs, or normalising values before further processing.

func MapRef

func MapRef[T1 any, T2 any](s []T1, f MapRefFunc[T1, T2]) []T2

MapRef applies a reference-based mapping function to s and returns the mapped slice.

This is useful when eager slice transformation should reuse logic written for pointer-oriented mappers.

func MapRefWithError

func MapRefWithError[T1 any, T2 any](s []T1, f MapRefWithErrorFunc[T1, T2]) (result []T2, err error)

MapRefWithError applies a reference-based mapper that may return an error. If the mapper returns nil or an error, processing stops and an error is returned.

This is useful when eager slice transformation should stop as soon as an invalid or missing mapped value is encountered.

func MapSequence

func MapSequence[T1 any, T2 any](s iter.Seq[T1], f MapFunc[T1, T2]) iter.Seq[T2]

MapSequence maps each element of s using f and returns a sequence of mapped values.

This is useful when data should be transformed lazily, for example while streaming over iterators or when chaining other sequence operations.

Reference documentation:

func MapSequenceRef

func MapSequenceRef[T1 any, T2 any](s iter.Seq[T1], f MapRefFunc[T1, T2]) iter.Seq[T2]

MapSequenceRef maps a sequence by applying a reference-based mapper to each element.

This is useful when values are consumed lazily and the mapping logic is already written against pointers.

func MapSequenceRefWithError

func MapSequenceRefWithError[T1 any, T2 any](s iter.Seq[T1], f MapRefWithErrorFunc[T1, T2]) iter.Seq[T2]

MapSequenceRefWithError maps a sequence using a reference-based mapper which may return an error. Mapping stops if the mapper returns an error, returns nil, or if the consumer declines the yielded value.

This is useful when lazy iteration and pointer-oriented mapping need to be combined with validation or other error-producing transformations.

func MapSequenceWithError

func MapSequenceWithError[T1 any, T2 any](s iter.Seq[T1], f MapWithErrorFunc[T1, T2]) iter.Seq[T2]

MapSequenceWithError maps each element of s using f, which may return an error. Mapping stops if f returns an error or if the consumer declines the yielded value.

func MapWithError

func MapWithError[T1 any, T2 any](s []T1, f MapWithErrorFunc[T1, T2]) (result []T2, err error)

MapWithError applies f to each element of s where f may return an error. If an error occurs, processing stops and the error is returned.

func Match

func Match[E any](e E, matches ...FilterFunc[E]) bool

Match returns true if any of the provided match predicates return true for e.

func MatchAll

func MatchAll[E any](e E, matches ...FilterFunc[E]) bool

MatchAll returns true only if all the provided match predicates return true for e.

func MergeBy

func MergeBy[T any, K comparable](items []T, keyFunc KeyFunc[T, K], merge MergeFunc[T]) (result []T)

MergeBy groups values by key and merges each group into one or more values.

Within each group, values are coalesced from left to right using merge.

Because grouping is map-based, the order of the returned groups is not guaranteed.

If items is nil, nil is returned. If items is empty, an empty slice is returned. If keyFunc or merge is nil, a clone of items is returned unchanged.

func MergeByRef

func MergeByRef[T any, K comparable](items []T, keyFunc KeyRefFunc[T, K], merge MergeRefFunc[T]) (result []T)

MergeByRef groups values by a reference-based key function and merges each group using a reference-based merge function.

func Negate

func Negate(values ...bool) []bool

Negate returns the slice with contrary values.

func Nth

func Nth[S ~[]E, E any](slice S, index int) (element E, ok bool)

Nth behaves like At.

func NthSequence

func NthSequence[E any](seq iter.Seq[E], index int) (element E, ok bool)

NthSequence behaves like AtSequence.

func OneHot

func OneHot(values ...bool) bool

OneHot returns true if one, and only one, of the supplied values is true. See https://en.wikipedia.org/wiki/One-hot

func Or

func Or(values ...bool) bool

Or performs an 'or' operation on an array of booleans.

func PairSplitModeStrings

func PairSplitModeStrings() []string

PairSplitModeStrings returns a slice of all String values of the enum

func ParseCommaSeparatedList

func ParseCommaSeparatedList(input string) []string

ParseCommaSeparatedList returns the list of string separated by a comma

func ParseCommaSeparatedListOfPairsToMap

func ParseCommaSeparatedListOfPairsToMap(input, pairSeparator string) (pairs map[string]string, err error)

ParseCommaSeparatedListOfPairsToMap returns a map of key value pairs from a string containing a comma separated list of pairs using pairSeparator to separate between keys and values e.g. key1=value1,key2=value2

func ParseCommaSeparatedListToMap

func ParseCommaSeparatedListToMap(input string) (pairs map[string]string, err error)

ParseCommaSeparatedListToMap returns a map of key value pairs from a string containing a comma separated list

func ParseListWithCleanup

func ParseListWithCleanup(input string, sep string) (newS []string)

ParseListWithCleanup splits a string into a list like strings.Split but also removes any whitespace surrounding the different items for example, ParseListWithCleanup("a, b , c", ",") returns []{"a","b","c"}

func ParseListWithCleanupKeepBlankLines

func ParseListWithCleanupKeepBlankLines(input string, sep string) (newS []string)

ParseListWithCleanupKeepBlankLines splits a string into a list like strings.Split but also removes any whitespace surrounding the different items unless the entire item is whitespace in which case it is converted to an empty string. For example, ParseListWithCleanupKeepBlankLines("a, b , c", ",") returns []{"a","b","c"} ParseListWithCleanupKeepBlankLines("a, b , , c", ",") returns []{"a","b", "", "c"}

func Partition

func Partition[S ~[]E, E any](slice S, predicate Predicate[E]) (matched S, unmatched S)

Partition splits slice into matching and non-matching values according to predicate.

func PartitionRef

func PartitionRef[S ~[]E, E any](slice S, predicate PredicateRef[E]) (matched S, unmatched S)

PartitionRef behaves like Partition but accepts a reference-based predicate.

func PartitionRefSequence

func PartitionRefSequence[S ~[]E, E any](seq iter.Seq[E], predicate PredicateRef[E]) (matched S, unmatched S)

PartitionRefSequence behaves like PartitionSequence but accepts a reference-based predicate.

func PartitionSequence

func PartitionSequence[S ~[]E, E any](seq iter.Seq[E], predicate Predicate[E]) (matched S, unmatched S)

PartitionSequence splits seq into matching and non-matching values according to predicate.

func PopAt

func PopAt[S ~[]E, E any](slice S, index int) (element E, remaining S, ok bool)

PopAt removes and returns the element at index from slice.

Negative indices follow the same Python-style semantics as At.

func Random

func Random[S ~[]E, E any](slice S) (E, bool)

Random returns a random element from the slice.

This is useful when one arbitrary element should be sampled from a slice, such as choosing a test case, backend, worker, or candidate value.

The first return value is the selected element. The second return value reports whether an element could be selected. If the slice is empty, Random returns the zero value of E and false.

Reference documentation:

func Range

func Range[T safecast.IConvertible](start, stop T, step *T) (result []T)

Range returns a slice of integers similar to Python's built-in range(). https://docs.python.org/2/library/functions.html#range

Note: The stop value is always exclusive.

func RangeSequence

func RangeSequence[T safecast.IConvertible](start, stop T, step *T) iter.Seq[T]

RangeSequence returns an iterator over a range

func Reduce

func Reduce[T1, T2 any](s []T1, accumulator T2, f ReduceFunc[T1, T2]) T2

Reduce folds over the slice s using f, starting with accumulator.

This is useful when a collection needs to be collapsed into one value, for example summing values, building a lookup map, or computing a derived result from many elements.

Reference documentation:

func ReducesSequence

func ReducesSequence[T1, T2 any](s iter.Seq[T1], accumulator T2, f ReduceFunc[T1, T2]) T2

ReducesSequence folds over a sequence using f, starting with accumulator.

This is the sequence-oriented counterpart to Reduce and is useful when values are consumed lazily rather than from a prebuilt slice, such as values flowing through iterators or other on-demand pipelines.

Reference documentation:

func Reject

func Reject[S ~[]E, E any](s S, f FilterFunc[E]) S

Reject returns elements for which f returns false (the inverse of Filter). This returns a new slice rather than modifying the input.

func RejectRef

func RejectRef[S ~[]E, E any](s S, f FilterRefFunc[E]) S

RejectRef behaves like Reject but accepts a reference-based predicate.

func RejectSequence

func RejectSequence[E any](s iter.Seq[E], f FilterFunc[E]) iter.Seq[E]

RejectSequence returns a sequence that yields elements for which f returns false.

This is useful when the complement of a filter condition should be applied in a lazy pipeline.

func Remove

func Remove(slice []string, val ...string) []string

Remove looks for elements in a slice. If they're found, it will remove them.

func Reverse

func Reverse[S ~[]E, E any](s S) S

Reverse returns a reversed copy of s.

func ReverseSequence

func ReverseSequence[E any](seq iter.Seq[E]) iter.Seq[E]

ReverseSequence yields the values of seq in reverse order.

func Sequence2OrEmpty

func Sequence2OrEmpty[K any, V any](s iter.Seq2[K, V]) iter.Seq2[K, V]

Sequence2OrEmpty returns s when it is non-nil, otherwise it returns an empty key/value sequence.

This is useful when consuming code wants a guaranteed safe `iter.Seq2` value that can be ranged over without needing a separate nil check.

func SequenceOrEmpty

func SequenceOrEmpty[T any](s iter.Seq[T]) iter.Seq[T]

SequenceOrEmpty returns s when it is non-nil, otherwise it returns an empty sequence.

This is useful when consuming code wants a guaranteed safe `iter.Seq` value that can be ranged over without needing a separate nil check.

func Shuffle

func Shuffle[S ~[]E, E any](slice S) S

Shuffle returns a shuffled copy of the slice.

This is useful when the same elements should be processed in a random order without mutating the original slice.

Reference documentation:

func Slice

func Slice[S ~[]E, E any](slice S, start, stop int) S

Slice returns a subsection of slice using Python-style indexing semantics.

Negative indices are interpreted relative to the end of the slice and the stop index is exclusive. Out-of-range bounds are clamped to the valid range. If the resulting bounds are empty, an empty slice is returned.

References:

func SliceSequence

func SliceSequence[E any](seq iter.Seq[E], start, stop int) iter.Seq[E]

SliceSequence returns a subsection of seq using Python-style indexing semantics.

func StrictRefMatch

func StrictRefMatch[E comparable](a, b *E) (bool, error)

StrictRefMatch reports whether two references are equal using field.Equal.

func SymmetricDifference

func SymmetricDifference[T comparable](slice1, slice2 []T) []T

SymmetricDifference returns distinct values that are present in either slice1 or slice2 but not in both.

func Take

func Take[S ~[]E, E any](slice S, count int) S

Take returns the first count elements of slice.

func TakeSequence

func TakeSequence[E any](seq iter.Seq[E], count int) iter.Seq[E]

TakeSequence yields the first count elements of seq.

func TakeWhile

func TakeWhile[S ~[]E, E any](slice S, predicate Predicate[E]) S

TakeWhile returns the leading elements of slice that satisfy predicate.

func TakeWhileSequence

func TakeWhileSequence[E any](seq iter.Seq[E], predicate Predicate[E]) iter.Seq[E]

TakeWhileSequence yields the leading elements of seq that satisfy predicate.

func Union

func Union[T comparable](slice1, slice2 []T) []T

Union returns the union of slice1 and slice2, containing only unique values. The order of elements is not guaranteed.

func Unique

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

Unique returns the distinct values from the provided sequence. The order of elements is not guaranteed.

func UniqueBy

func UniqueBy[S ~[]E, E any, K comparable](slice S, keyFunc KeyFunc[E, K]) S

UniqueBy returns the first occurrence of each unique derived key.

This is useful when values should remain in input order while duplicates are removed based on a derived property such as an ID, normalised string, or computed category.

Reference documentation:

func UniqueByRef

func UniqueByRef[S ~[]E, E any, K comparable](slice S, keyFunc KeyRefFunc[E, K]) S

UniqueByRef behaves like UniqueBy but accepts a reference-based key function.

func UniqueByRefSequence

func UniqueByRefSequence[E any, K comparable](sequence iter.Seq[E], keyFunc KeyRefFunc[E, K]) []E

UniqueByRefSequence behaves like UniqueBySequence but accepts a reference-based key function.

func UniqueBySequence

func UniqueBySequence[E any, K comparable](sequence iter.Seq[E], keyFunc KeyFunc[E, K]) []E

UniqueBySequence returns the first occurrence of each unique derived key from a sequence.

func UniqueEntries

func UniqueEntries[T comparable](slice []T) []T

UniqueEntries returns a slice containing the distinct values from the provided slice. The order of elements is not guaranteed.

func Xor

func Xor(values ...bool) bool

Xor performs a `xor` on an array of booleans. This behaves like an XOR gate; it returns true if the number of true values is odd, and false if the number of true values is zero or even.

func Zip

func Zip[S1 ~[]E1, S2 ~[]E2, E1, E2 any](left S1, right S2) iter.Seq2[E1, E2]

Zip yields pairs of corresponding values from left and right.

Iteration stops when either side runs out of values.

func ZipSequence

func ZipSequence[E1, E2 any](left iter.Seq[E1], right iter.Seq[E2]) iter.Seq2[E1, E2]

ZipSequence yields pairs of corresponding values from left and right.

Iteration stops when either side runs out of values.

Types

type Conditions

type Conditions []bool

func NewConditions

func NewConditions(capacity int) Conditions

NewConditions creates a set of conditions.

func NewConditionsFromValues

func NewConditionsFromValues(conditions ...bool) Conditions

NewConditionsFromValues creates a set of conditions.

func (*Conditions) Add

func (c *Conditions) Add(conditions ...bool) Conditions

Add adds conditions and returns itself.

func (*Conditions) All

func (c *Conditions) All() bool

All returns true if all conditions are true.

func (*Conditions) And

func (c *Conditions) And() bool

And performs an `and` operation on all conditions

func (*Conditions) Any

func (c *Conditions) Any() bool

Any returns true if there is at least one condition which is true.

func (*Conditions) Concat

func (c *Conditions) Concat(more *Conditions) Conditions

Concat concatenates conditions and returns itself.

func (*Conditions) Contains

func (c *Conditions) Contains(condition bool) bool

Contains returns whether the conditions collection contains the value of a condition.

func (*Conditions) ForEach

func (c *Conditions) ForEach(each func(bool) error) error

ForEach will execute function each() on every condition unless an error is returned and will end add this point.

func (*Conditions) Negate

func (c *Conditions) Negate() Conditions

Negate returns a new set of conditions with negated values.

func (*Conditions) OneHot

func (c *Conditions) OneHot() bool

OneHot performs an `OneHot` operation on all conditions

func (*Conditions) Or

func (c *Conditions) Or() bool

Or performs an `Or` operation on all conditions

func (*Conditions) Xor

func (c *Conditions) Xor() bool

Xor performs a `Xor` operation on all conditions

type FilterFunc

type FilterFunc[E any] func(E) bool

FilterFunc defines a function that evaluates a value and returns true when the value satisfies the condition.

Filter predicates are useful for selecting only the elements that should be kept, such as enabled records, matching names, valid values, or items within a threshold.

func OppositeFunc

func OppositeFunc[E any](f FilterFunc[E]) FilterFunc[E]

OppositeFunc returns a predicate that negates the result of f.

type FilterRefFunc

type FilterRefFunc[E any] func(*E) bool

FilterRefFunc defines a function that evaluates a pointer to a value and returns true when the referenced value satisfies the condition.

Reference-based predicates are useful when the predicate should be able to work with optional values, share logic with other pointer-oriented helpers, or avoid copying larger element values.

type KeyFunc

type KeyFunc[T1 any, T2 comparable] = MapFunc[T1, T2]

KeyFunc defines a function that maps an element to a comparable key.

Key functions are useful when values need to be grouped, counted, or deduplicated based on a derived identity such as an ID, category, or normalised form.

type KeyRefFunc

type KeyRefFunc[T1 any, T2 comparable] func(*T1) T2

KeyRefFunc defines a function that maps a pointer to a value to a comparable key.

Reference-based key functions are useful when grouping or counting logic is naturally written against optional or pointer-based values.

type MapFunc

type MapFunc[T1, T2 any] func(T1) T2

MapFunc defines a function that maps a value of type T1 to type T2.

Mapping functions are useful for transforming collections from one shape into another, such as extracting a field, converting one type to another, or preparing values for serialisation or display.

func Combine

func Combine[T any](functions ...MapFunc[T, T]) MapFunc[T, T]

Combine composes mapping functions of the same input/output type.

Functions are applied from right to left, so `Combine(f1, f2, f3)(value)` is equivalent to `f1(f2(f3(value)))`. This corresponds to the composition `f1 o f2 o f3`.

If no functions are supplied, the identity mapping is returned.

Reference documentation:

func IdentityMapFunc

func IdentityMapFunc[T any]() MapFunc[T, T]

IdentityMapFunc returns a mapping function that returns its input unchanged.

type MapRefFunc

type MapRefFunc[T1, T2 any] func(*T1) *T2

MapRefFunc defines a mapping function that accepts a pointer to T1 and returns a pointer to T2.

Reference-based mappers are useful when the mapping logic naturally works on pointers, when a value may be optional, or when larger values should not be copied unnecessarily.

func CombineRef

func CombineRef[T any](functions ...MapRefFunc[T, T]) MapRefFunc[T, T]

CombineRef composes reference-based mapping functions of the same input/output type.

Functions are applied from right to left, so `CombineRef(f1, f2, f3)(value)` is equivalent to `f1(f2(f3(value)))`. This corresponds to the composition `f1 o f2 o f3`.

If no functions are supplied, the identity mapping is returned.

Reference documentation:

type MapRefWithErrorFunc

type MapRefWithErrorFunc[T1, T2 any] func(*T1) (*T2, error)

MapRefWithErrorFunc defines a reference-based mapping function that may return an error.

func CombineRefWithError

func CombineRefWithError[T any](functions ...MapRefWithErrorFunc[T, T]) MapRefWithErrorFunc[T, T]

CombineRefWithError composes reference-based error-returning mapping functions of the same input/output type.

Functions are applied from right to left, so `CombineRefWithError(f1, f2, f3)(value)` is equivalent to `f1(f2(f3(value)))`. This corresponds to the composition `f1 o f2 o f3`.

If any function returns an error, composition stops immediately and the error is returned.

If no functions are supplied, the identity mapping is returned.

Reference documentation:

type MapWithErrorFunc

type MapWithErrorFunc[T1, T2 any] func(T1) (T2, error)

MapWithErrorFunc defines a mapping function that may return an error.

func CombineWithError

func CombineWithError[T any](functions ...MapWithErrorFunc[T, T]) MapWithErrorFunc[T, T]

CombineWithError composes error-returning mapping functions of the same input/output type.

Functions are applied from right to left, so `CombineWithError(f1, f2, f3)(value)` is equivalent to `f1(f2(f3(value)))`. This corresponds to the composition `f1 o f2 o f3`.

If any function returns an error, composition stops immediately and the error is returned.

If no functions are supplied, the identity mapping is returned.

Reference documentation:

type MatchFunc

type MatchFunc[E any] func(E, E) (bool, error)

MatchFunc compares two values of type E and reports whether they match. It may return an error if the comparison requires additional processing, such as compiling or evaluating a regular expression.

var StringCaseInsensitiveMatch MatchFunc[string] = func(a, b string) (bool, error) { return strings.EqualFold(a, b), nil }

StringCaseInsensitiveMatch reports whether two strings are equal but ignoring their case.

var StringCleanCaseInsensitiveMatch MatchFunc[string] = func(a, b string) (bool, error) {
	return StringCaseInsensitiveMatch(strings.TrimSpace(a), strings.TrimSpace(b))
}

StringCleanCaseInsensitiveMatch reports whether two strings are equal after trimming surrounding whitespace and ignoring their case.

var StringCleanMatch MatchFunc[string] = func(a, b string) (bool, error) { return StringMatch(strings.TrimSpace(a), strings.TrimSpace(b)) }

StringCleanMatch reports whether two strings are exactly equal after trimming surrounding whitespace.

var StringMatch MatchFunc[string] = func(a, b string) (bool, error) { return a == b, nil }

StringMatch reports whether two strings are exactly equal.

var StringRegexMatch MatchFunc[string] = regexp.MatchString

StringRegexMatch reports whether a string matches the provided regular expression pattern. the pattern being the first argument.

type MatchRefFunc

type MatchRefFunc[E any] func(*E, *E) (bool, error)

MatchRefFunc compares two references to values of type E and reports whether they match. It may return an error if the comparison requires additional processing before the match can be determined.

type MatchingFunction

type MatchingFunction[E any] = FilterFunc[E]

MatchingFunction is an alias for FilterFunc to express whether a single value matches a condition.

type MergeFunc

type MergeFunc[T any] func(e1, e2 T) (merged T, compatible bool)

MergeFunc combines two values of the same type into one.

type MergeRefFunc

type MergeRefFunc[T any] func(e1, e2 *T) (merged *T, compatible bool)

MergeRefFunc combines two references to values of the same type into one.

type OperationFunc

type OperationFunc[E any] func(E) error

OperationFunc defines an operation on a value that may return an error.

type OperationRefFunc

type OperationRefFunc[E any] func(*E) error

OperationRefFunc defines an operation on a pointer to a value that may return an error.

type OperationWithoutErrorFunc

type OperationWithoutErrorFunc[E any] func(E)

OperationWithoutErrorFunc defines an operation on a value that does not return an error.

type OperationWithoutErrorRefFunc

type OperationWithoutErrorRefFunc[E any] func(*E)

OperationWithoutErrorRefFunc defines an operation on a pointer that does not return an error.

type PairOption

type PairOption func(*PairOptions) *PairOptions

PairOption applies configuration to PairOptions for pair parsing behaviour.

func WithPairSeparator

func WithPairSeparator(sep string) PairOption

WithPairSeparator sets the separator used to split key/value pair entries.

func WithPairSplitMode

func WithPairSplitMode(mode PairSplitMode) PairOption

WithPairSplitMode sets how a pair entry is split into key and value.

type PairOptions

type PairOptions struct {
	PairSeparator string
	// contains filtered or unexported fields
}

type PairSplitMode

type PairSplitMode int
const (
	// SplitAllMatch splits each pair item on all matches of the separator.
	// The item is valid only if it resolves to exactly two non-empty parts after cleanup.
	SplitAllMatch PairSplitMode = iota
	// SplitFirstMatch splits each pair item only on the first match of the separator.
	// This allows separator characters to remain in the value portion.
	SplitFirstMatch
)

func PairSplitModeString

func PairSplitModeString(s string) (PairSplitMode, error)

PairSplitModeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func PairSplitModeValues

func PairSplitModeValues() []PairSplitMode

PairSplitModeValues returns all values of the enum

func (PairSplitMode) IsAPairSplitMode

func (i PairSplitMode) IsAPairSplitMode() bool

IsAPairSplitMode returns "true" if the value is listed in the enum definition. "false" otherwise

func (PairSplitMode) MarshalJSON

func (i PairSplitMode) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for PairSplitMode

func (PairSplitMode) MarshalText

func (i PairSplitMode) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for PairSplitMode

func (PairSplitMode) MarshalYAML

func (i PairSplitMode) MarshalYAML() (interface{}, error)

MarshalYAML implements a YAML Marshaler for PairSplitMode

func (PairSplitMode) String

func (i PairSplitMode) String() string

func (*PairSplitMode) UnmarshalJSON

func (i *PairSplitMode) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for PairSplitMode

func (*PairSplitMode) UnmarshalText

func (i *PairSplitMode) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for PairSplitMode

func (*PairSplitMode) UnmarshalYAML

func (i *PairSplitMode) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements a YAML Unmarshaler for PairSplitMode

type Predicate

type Predicate[E any] = FilterFunc[E]

Predicate is an alias for FilterFunc to express boolean tests.

type PredicateRef

type PredicateRef[E any] = FilterRefFunc[E]

PredicateRef is an alias for FilterRefFunc to express boolean tests on references.

type ReduceFunc

type ReduceFunc[T1, T2 any] func(T2, T1) T2

ReduceFunc defines a reducer that combines an accumulator and an element to produce a new accumulator.

Reducers are useful for aggregating collections into a single result, such as totals, counts, grouped values, flattened structures, or derived summary objects.

type ReduceRefFunc

type ReduceRefFunc[T1, T2 any] func(*T2, *T1) *T2

ReduceRefFunc defines a reducer that operates on references.

Reference-based reducers are useful when the accumulator or elements are more naturally handled as pointers, for example when building up mutable state or sharing reducer logic with other pointer-oriented helpers.

Directories

Path Synopsis
* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors.
* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors.
Package pagination provides a ways to iterate over collections.
Package pagination provides a ways to iterate over collections.
* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors.
* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors.
* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors.
* Copyright (C) 2020-2026 Arm Limited or its affiliates and Contributors.

Jump to

Keyboard shortcuts

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