opentofu/internal/experiments/set.go
Martin Atkins 26e5320a78 Move experiments/ to internal/experiments/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00

47 lines
1.0 KiB
Go

package experiments
// Set is a collection of experiments where every experiment is either a member
// or not.
type Set map[Experiment]struct{}
// NewSet constructs a new Set with the given experiments as its initial members.
func NewSet(exps ...Experiment) Set {
ret := make(Set)
for _, exp := range exps {
ret.Add(exp)
}
return ret
}
// SetUnion constructs a new Set containing the members of all of the given
// sets.
func SetUnion(sets ...Set) Set {
ret := make(Set)
for _, set := range sets {
for exp := range set {
ret.Add(exp)
}
}
return ret
}
// Add inserts the given experiment into the set.
//
// If the given experiment is already present then this is a no-op.
func (s Set) Add(exp Experiment) {
s[exp] = struct{}{}
}
// Remove takes the given experiment out of the set.
//
// If the given experiment not already present then this is a no-op.
func (s Set) Remove(exp Experiment) {
delete(s, exp)
}
// Has tests whether the given experiment is in the receiving set.
func (s Set) Has(exp Experiment) bool {
_, ok := s[exp]
return ok
}