Skip to content

Instantly share code, notes, and snippets.

@crhntr
Created December 11, 2022 21:38
Show Gist options
  • Save crhntr/d6d51d1b1eda04c82aa1e5d8ca606074 to your computer and use it in GitHub Desktop.
Save crhntr/d6d51d1b1eda04c82aa1e5d8ca606074 to your computer and use it in GitHub Desktop.
package main
import "golang.org/x/exp/maps"
type Set[T comparable] map[T]struct{}
func (s Set[T]) Add(v T) { s[v] = struct{}{} }
func (s Set[T]) Remove(v T) { delete(s, v) }
func (s Set[T]) Has(v T) bool { _, has := s[v]; return has }
func (s Set[T]) List() []T { return maps.Keys(s) }
func (s Set[T]) IsEmpty() bool { return len(s) == 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment