Documentation ¶
Index ¶
- type Set
- func (s Set[T]) Add(items ...T)
- func (s Set[T]) Contains(items ...T) bool
- func (s Set[T]) ContainsAny(items ...T) bool
- func (s Set[T]) Copy() Set[T]
- func (s Set[T]) Equals(other Set[T]) bool
- func (s Set[T]) IsSubSet(other Set[T]) bool
- func (s Set[T]) IsSuperSet(other Set[T]) bool
- func (s Set[T]) MarshalJSON() ([]byte, error)
- func (s Set[T]) Merge(other Set[T])
- func (s Set[T]) Remove(items ...T)
- func (s Set[T]) Separate(other Set[T])
- func (s Set[T]) Slice() []T
- func (s Set[T]) String() string
- func (s *Set[T]) UnmarshalJSON(bytes []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] map[T]struct{}
Set is an unordered collection of distinct comparable items. Common uses include membership testing, removing duplicates from sequence, and doing boolean set operations like Intersection and Union.
func Difference ¶
func Difference[T comparable](lhs Set[T], others ...Set[T]) Set[T]
Difference returns a new set which contains items that are in the first Set but not in the others.
func Intersection ¶
func Intersection[T comparable](sets ...Set[T]) Set[T]
Intersection returns a new Set which contains items that only exist in all given sets.
func SymmetricDifference ¶
func SymmetricDifference[T comparable](lhs, rhs Set[T]) Set[T]
SymmetricDifference returns a new set that contains elements from either passed set but not both.
func Union ¶
func Union[T comparable](sets ...Set[T]) Set[T]
Union is the merger of multiple sets. It returns a new Set with all elements in all the sets passed.
func (Set[T]) Add ¶
func (s Set[T]) Add(items ...T)
Add includes the specified items (one or many) to the Set s. Set s is modified in place. If passed nothing it silently returns.
func (Set[T]) Contains ¶
Contains tests if Set s contains all items passed. It returns false if nothing is passed.
func (Set[T]) ContainsAny ¶
ContainsAny tests if Set s contains any of the items passed. It returns false of nothing is passed.
func (Set[T]) Equals ¶
Equals tests whether s and other are the same size and contain the same items.
func (Set[T]) IsSuperSet ¶ added in v0.2.0
IsSuperSet tests if every element of other exists in s.
func (Set[T]) MarshalJSON ¶ added in v1.0.0
func (Set[T]) Merge ¶
Merge adds all items from Set other into Set s. This works just like Union, but it applies to Set s in place.
func (Set[T]) Remove ¶
func (s Set[T]) Remove(items ...T)
Remove deletes the specified items (one or many) from the Set s. Set s is modified in place. If passed nothing it silently returns.
func (Set[T]) Separate ¶
Separate removes items in Set other from Set s. This works just like Difference but applies to the Set in place.
func (Set[T]) Slice ¶
func (s Set[T]) Slice() []T
Slice returns a Slice of all items in Set s as a []T.
func (*Set[T]) UnmarshalJSON ¶ added in v1.0.0
UnmarshalJSON implements the json.Unmarshaler interface turns the slice back to a Set.