github.com/kevinklinger/open_terraform@v1.3.6/noninternal/experiments/set.go (about)

     1  package experiments
     2  
     3  // Set is a collection of experiments where every experiment is either a member
     4  // or not.
     5  type Set map[Experiment]struct{}
     6  
     7  // NewSet constructs a new Set with the given experiments as its initial members.
     8  func NewSet(exps ...Experiment) Set {
     9  	ret := make(Set)
    10  	for _, exp := range exps {
    11  		ret.Add(exp)
    12  	}
    13  	return ret
    14  }
    15  
    16  // SetUnion constructs a new Set containing the members of all of the given
    17  // sets.
    18  func SetUnion(sets ...Set) Set {
    19  	ret := make(Set)
    20  	for _, set := range sets {
    21  		for exp := range set {
    22  			ret.Add(exp)
    23  		}
    24  	}
    25  	return ret
    26  }
    27  
    28  // Add inserts the given experiment into the set.
    29  //
    30  // If the given experiment is already present then this is a no-op.
    31  func (s Set) Add(exp Experiment) {
    32  	s[exp] = struct{}{}
    33  }
    34  
    35  // Remove takes the given experiment out of the set.
    36  //
    37  // If the given experiment not already present then this is a no-op.
    38  func (s Set) Remove(exp Experiment) {
    39  	delete(s, exp)
    40  }
    41  
    42  // Has tests whether the given experiment is in the receiving set.
    43  func (s Set) Has(exp Experiment) bool {
    44  	_, ok := s[exp]
    45  	return ok
    46  }