Documentation
¶
Index ¶
- func CheckDuplicateValues[T comparable](slices ...[]T) error
- func MakeSlice[T any](n int, newFn func() *T) []*T
- func RemoveDuplicateIDs(in []*contract.ID) []*contract.ID
- func RemoveDuplicates[T comparable](in []T) []T
- func RemoveDuplicatesBy[T any, K comparable](in []T, key func(T) K) []T
- func RemoveIDs(a, b []contract.ID) []contract.ID
- func RemoveSliceElements[T comparable](a, b []T) []T
- type SliceComparisonResult
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
MakeSlice returns a slice of length n with each element initialized by calling newFn.
func RemoveDuplicateIDs ¶ added in v0.1.781
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 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.