MCPcopy Create free account
hub / github.com/github/gh-aw / Exclude

Function Exclude

pkg/sliceutil/sliceutil.go:123–140  ·  view source on GitHub ↗

Exclude returns a new slice containing the items from base that do not appear in the exclude set. Order of remaining items is preserved. Always returns a fresh slice (never aliases base) even when no items are removed.

(base []T, exclude ...T)

Source from the content-addressed store, hash-verified

121// in the exclude set. Order of remaining items is preserved.
122// Always returns a fresh slice (never aliases base) even when no items are removed.
123func Exclude[T comparable](base []T, exclude ...T) []T {
124 if len(exclude) == 0 {
125 return append([]T(nil), base...)
126 }
127
128 excluded := make(map[T]struct{}, len(exclude))
129 for _, item := range exclude {
130 excluded[item] = struct{}{}
131 }
132
133 result := make([]T, 0, len(base))
134 for _, item := range base {
135 if _, isExcluded := excluded[item]; !isExcluded {
136 result = append(result, item)
137 }
138 }
139 return result
140}

Callers 4

TestExcludeFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestExcludeFunction · 0.68