Skip to content

Commit

Permalink
feat(xmaps): add BuildSet helper to build a set from slice
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Sep 13, 2022
1 parent ebd8d95 commit 5fb3207
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/xmaps/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package xmaps

// BuildSet builds a set from the given values.
func BuildSet[K comparable](s ...K) map[K]struct{} {
r := make(map[K]struct{}, len(s))
for _, v := range s {
r[v] = struct{}{}
}
return r
}

0 comments on commit 5fb3207

Please sign in to comment.