sliceutil

package
v0.0.0-...-7d7435f Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllOf

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

AllOf returns true if all elements in slice satisfy the predicate function.

func ArgSort

func ArgSort[T any](slice []T, less func(a, b T) bool) []int

func CollectMapValues

func CollectMapValues[K comparable, V any](m map[K]V) []V

func ContainsAll

func ContainsAll[S ~[]E, E comparable](super S, sub S) bool

Contains reports whether all elements in sub are present in super.

func Exclude

func Exclude[S ~[]E, E comparable](set S, excludeElement E) S

Exclude returns a new slice containing elements in set that are not equal to excludeElement.

func Filter

func Filter[T any](slice []T, predicate func(T) bool) []T

Filter returns a new slice containing only elements that satisfy the predicate function. Returns nil if the input slice is empty.

func InplaceTake

func InplaceTake[T any](slice []T, predicate []bool) []T

InplaceTake modifies the slice in place to contain only elements where the corresponding element in predicate is true. Please ensure len(slice) <= len(predicate) before calling this function.

func Intersection

func Intersection[S ~[]E, E comparable](a S, b S) S

func JoinStringers

func JoinStringers[T fmt.Stringer](elements []T, sep string) string

func MergeMaps

func MergeMaps[K comparable, V any](map1, map2 map[K]V) map[K]V

func MergeSlices

func MergeSlices[T any](slices ...[]T) []T

func SliceDeDup

func SliceDeDup[S ~[]E, E cmp.Ordered](s S) S

SliceDeDup removes duplicate elements from a slice.

func SortMapKeyForDeterminism

func SortMapKeyForDeterminism[k cmp.Ordered, v any](m map[k]v) []k

SortMapKeyForDeterminism returns a slice of keys from a map in sorted order.

func SortedMap

func SortedMap[k cmp.Ordered, v any](m map[k]v) iter.Seq2[k, v]

SortedMap returns an iterator that yields key-value pairs from a map in sorted key order

func Subtraction

func Subtraction[S ~[]E, E comparable](a S, b S) S

Subtraction returns a new slice containing elements in a that are not present in b.

func Take

func Take[T any](slice []T, predicate []bool) []T

Take returns a new slice containing elements from slice where the corresponding element in predicate is true. Please ensure len(slice) <= len(predicate) before calling this function.

func TakeByIndices

func TakeByIndices[T any](slice []T, indices []int) ([]T, error)

func UnOrderedSliceEqual

func UnOrderedSliceEqual[S ~[]E, E cmp.Ordered](s1, s2 S) bool

func ValueSortedByMapKey

func ValueSortedByMapKey[k cmp.Ordered, v any](m map[k]v) iter.Seq[v]

ValueSortedByMapKey returns an iterator that yields values from a map in sorted key order.

Types

This section is empty.

Jump to

Keyboard shortcuts

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