sliceutil

package
v0.1.924 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDuplicateValues

func CheckDuplicateValues[T comparable](slices ...[]T) error

CheckDuplicateValues checks for duplicates across multiple slices of type T. Returns an error if at least one value is duplicated across a minimum of two slices or in the same slice.

func MakeSlice added in v0.1.842

func MakeSlice[T any](n int, newFn func() *T) []*T

MakeSlice returns a slice of length n with each element initialized by calling newFn.

func RemoveDuplicateIDs added in v0.1.781

func RemoveDuplicateIDs(in []*contract.ID) []*contract.ID

RemoveDuplicateIDs deduplicates []*contract.ID by their string value (nil collapses to empty).

func RemoveDuplicates

func RemoveDuplicates[T comparable](in []T) []T

RemoveDuplicates returns a new slice with unique comparable values.

func RemoveDuplicatesBy added in v0.1.781

func RemoveDuplicatesBy[T any, K comparable](in []T, key func(T) K) []T

RemoveDuplicatesBy returns a new slice with duplicates removed using a key selector.

func RemoveIDs added in v0.1.349

func RemoveIDs(a, b []contract.ID) []contract.ID

RemoveIDs removes IDs of the second slice from the first slice.

func RemoveSliceElements

func RemoveSliceElements[T comparable](a, b []T) []T

RemoveSliceElements removes elements of the second slice from the first slice.

Types

type SliceComparisonResult

type SliceComparisonResult[T comparable] struct {
	DifferenceA []T // Elements in sliceA but not in sliceB.
	DifferenceB []T // Elements in sliceB but not in sliceA.
	Similar     []T // Elements present in both slices.
}

SliceComparisonResult holds the differences and similarities between two slices.

func CompareIDPointerSlices added in v0.1.783

func CompareIDPointerSlices(a, b []*contract.ID) SliceComparisonResult[*contract.ID]

CompareIDPointerSlices compares two slices of *contract.ID by their string value (nil -> "").

func CompareSlices

func CompareSlices[T comparable](a, b []T) SliceComparisonResult[T]

CompareSlices returns elements unique to A, unique to B, and in both.

func CompareSlicesBy added in v0.1.783

func CompareSlicesBy[T comparable, K comparable](a, b []T, key func(T) K) SliceComparisonResult[T]

CompareSlicesBy compares slices using a key selector and returns differences/similarities.

Jump to

Keyboard shortcuts

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