The sliceutil package provides generic utility functions for working with slices and maps.
All functions in this package are pure: they never modify their input. They are generic and work with any element type using Go's type-parameter syntax.
import "github.com/github/gh-aw/pkg/sliceutil"
// Filter a slice
numbers := []int{1, 2, 3, 4, 5}
evens := sliceutil.Filter(numbers, func(n int) bool { return n%2 == 0 })
// evens = [2, 4]
// Map a slice
names := []string{"alice", "bob"}
upper := sliceutil.Map(names, strings.ToUpper)
// upper = ["ALICE", "BOB"]
// Deduplicate
items := []string{"a", "b", "a", "c"}
unique := sliceutil.Deduplicate(items)
// unique = ["a", "b", "c"]
// Merge unique values
merged := sliceutil.MergeUnique([]string{"a", "b"}, "b", "c")
// merged = ["a", "b", "c"]
// Exclude values
filtered := sliceutil.Exclude([]string{"a", "b", "c"}, "b")
// filtered = ["a", "c"]
// Sorted map keys
m := map[string]int{"banana": 2, "apple": 1}
keys := sliceutil.SortedKeys(m)
// keys = ["apple", "banana"]Internal:
github.com/github/gh-aw/pkg/logger— package-scoped logging used byDeduplicateandMergeUnique.
External:
- None beyond the Go standard library (
slices).
All functions in this package are pure and stateless — they create and return new slices or maps without writing to shared state. Callers MAY call any function concurrently without synchronization.
Anyis implemented viaslices.ContainsFuncfrom the standard library.Deduplicate,MergeUnique, andExcludeuse hash sets (map[T]struct{}) for O(n) behavior.SortedKeysdelegates toslices.Sorted(maps.Keys(m))from the standard library and returns a new sorted slice each call.- None of the other functions sort their output; callers that require sorted results should call
slices.Sorton the returned slice.
Reviewed against source on 2026-07-26; no public-contract deltas identified. Re-verified on 2026-08-14; still no public-contract deltas. Re-verified on 2026-08-29; still no public-contract deltas. Re-verified on 2026-09-03; still no public-contract deltas. Re-verified on 2026-09-08; still no public-contract deltas. Re-verified on 2026-09-13; still no public-contract deltas. Re-verified on 2026-09-23; still no public-contract deltas. Re-verified on 2026-09-28; still no public-contract deltas.
This specification is automatically maintained by the spec-extractor workflow.
