Documentation
¶
Overview ¶
Package sliceutil provides small, dependency-free generic slice helpers that the standard library's slices package does not cover — notably order-preserving deduplication of an unsorted slice and set intersection. They exist so services stop re-deriving the same map-backed loops locally.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dedupe ¶
func Dedupe[T comparable](in []T) []T
Dedupe returns a new slice with duplicate elements removed, preserving the first-seen order of the input. It returns nil for a nil or empty input. Unlike slices.Compact it does not require the input to be sorted, so it is safe for an arbitrarily-ordered slice where order must be preserved.
func Intersect ¶
func Intersect[T comparable](a, b []T) []T
Intersect returns the elements of a that are also present in b, preserving a's order. b is treated as a membership set, so its order and duplicates are irrelevant; a's duplicates are preserved (dedupe a first if that is not wanted). It returns nil when a is empty.
Types ¶
This section is empty.