github.com/golazy/golazy@v0.0.7-0.20221012133820-968fe65a0b65/lazysupport/set.go (about)

     1  package lazysupport
     2  
     3  type Void struct{}
     4  
     5  type Set[T comparable] map[T]Void
     6  
     7  func NewSet[T comparable](values ...T) Set[T] {
     8  	s := make(Set[T])
     9  	for _, key := range values {
    10  		s[key] = Void{}
    11  	}
    12  	return s
    13  }
    14  
    15  func (s Set[T]) Has(item T) bool {
    16  	_, ok := s[item]
    17  	return ok
    18  }