Documentation ΒΆ
Index ΒΆ
- type Set
- func (s *Set[T]) Add(items ...T)
- func (s *Set[T]) Contains(item T) bool
- func (s *Set[T]) Copy() *Set[T]
- func (s *Set[T]) Difference(others ...*Set[T]) *Set[T]
- func (s *Set[T]) Discard(items ...T)
- func (s *Set[T]) Equal(other *Set[T]) bool
- func (s *Set[T]) For(f func(item T))
- func (s *Set[T]) ForWithBreak(f func(item T) bool)
- func (s *Set[T]) Intersection(others ...*Set[T]) *Set[T]
- func (s *Set[T]) IsDisjoint(other *Set[T]) bool
- func (s *Set[T]) IsEmpty() bool
- func (s *Set[T]) IsSubset(other *Set[T]) bool
- func (s *Set[T]) IsSuperset(other *Set[T]) bool
- func (s *Set[T]) Items() []T
- func (s *Set[T]) Len() int
- func (s *Set[T]) MarshalJSON() ([]byte, error)
- func (s *Set[T]) Pop() (T, error)
- func (s *Set[T]) Remove(item T) error
- func (s *Set[T]) String() string
- func (s *Set[T]) SymmetricDifference(other *Set[T]) *Set[T]
- func (s *Set[T]) Union(others ...*Set[T]) *Set[T]
- func (s *Set[T]) UnmarshalJSON(b []byte) error
- func (s *Set[T]) Update(others ...*Set[T])
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type Set ΒΆ
type Set[T comparable] struct { // contains filtered or unexported fields }
Set represents a set data structure. You should not call it directly, use NewSet() or FromSlice()
func FromSlice ΒΆ
func FromSlice[T comparable](slice []T) *Set[T]
FromSlice returns a new Set with all the items of the slice.
func NewSet ΒΆ
func NewSet[T comparable](items ...T) *Set[T]
NewSet returns a new Set of the given items
func (*Set[T]) Difference ΒΆ
Difference returns a new Set of all the items in the current Set that are not in any of the others
func (*Set[T]) Discard ΒΆ
func (s *Set[T]) Discard(items ...T)
Discard removes item(s) from the Set if exist See also: Remove()
func (*Set[T]) Equal ΒΆ
Equal returns whether the current Set contains the same items as the other one
func (*Set[T]) For ΒΆ added in v1.1.0
func (s *Set[T]) For(f func(item T))
For runs a function on all the items in the Set
func (*Set[T]) ForWithBreak ΒΆ added in v1.1.0
ForWithBreak runs a function on all the items in the store if f returns false, the iteration stops
func (*Set[T]) Intersection ΒΆ
Intersection returns a new Set with the common items of the current set and all others.
func (*Set[T]) IsDisjoint ΒΆ
IsDisjoint returns whether the two Sets have no item in common
func (*Set[T]) IsSubset ΒΆ
IsSubset returns whether all the items of the current set exist in the other one
func (*Set[T]) IsSuperset ΒΆ
IsSuperset returns whether all the items of the other set exist in the current one
func (*Set[T]) MarshalJSON ΒΆ added in v1.2.0
func (*Set[T]) Pop ΒΆ
Pop removes an arbitrary item from the Set and returns it. Returns error if the Set is empty
func (*Set[T]) Remove ΒΆ
Remove removes a single item from the Set. Returns error if the item is not in the Set See also: Discard()
func (*Set[T]) SymmetricDifference ΒΆ
SymmetricDifference returns all the items that exist in only one of the Sets