Documentation ¶
Index ¶
- type Generic
- func (s *Generic[T]) Add(vals ...T)
- func (s Generic[T]) Contains(vals ...T) bool
- func (s Generic[T]) ContainsAny(vals ...T) bool
- func (s *Generic[T]) Delete(vals ...T)
- func (s Generic[T]) Diff(other Generic[T]) Generic[T]
- func (s Generic[T]) DiffSlice(other []T) Generic[T]
- func (s Generic[T]) FilterContains(slice []T) []T
- func (s Generic[T]) FilterNotContains(slice []T) []T
- func (s Generic[T]) Intersect(other Generic[T]) Generic[T]
- func (s Generic[T]) IntersectSlice(other []T) Generic[T]
- func (s Generic[T]) Iterate(fn func(T))
- func (s Generic[T]) Map() map[T]bool
- func (s Generic[T]) MarshalJSON() ([]byte, error)
- func (s Generic[T]) MarshalYAML() (any, error)
- func (s Generic[T]) Size() int
- func (s Generic[T]) Slice() []T
- func (s Generic[T]) Union(other Generic[T]) Generic[T]
- func (s Generic[T]) UnionSlice(other []T) Generic[T]
- func (s *Generic[T]) UnmarshalJSON(b []byte) error
- func (s *Generic[T]) UnmarshalYAML(unmarshal func(any) error) error
- type Int
- func (s Int) Del(vals ...int)
- func (s Int) Diff(other Int) Int
- func (s Int) DiffSlice(other []int) Int
- func (s Int) FilterExclude(slice []int) []int
- func (s Int) FilterInclude(slice []int) []int
- func (s Int) Intersect(other Int) Int
- func (s Int) IntersectSlice(other []int) Int
- func (s Int) Union(other Int) Int
- func (s Int) UnionSlice(other []int) Int
- type Int32
- func (s Int32) Del(vals ...int32)
- func (s Int32) Diff(other Int32) Int32
- func (s Int32) DiffSlice(other []int32) Int32
- func (s Int32) FilterExclude(slice []int32) []int32
- func (s Int32) FilterInclude(slice []int32) []int32
- func (s Int32) Intersect(other Int32) Int32
- func (s Int32) IntersectSlice(other []int32) Int32
- func (s Int32) Union(other Int32) Int32
- func (s Int32) UnionSlice(other []int32) Int32
- type Int64
- func (s Int64) Del(vals ...int64)
- func (s Int64) Diff(other Int64) Int64
- func (s Int64) DiffSlice(other []int64) Int64
- func (s Int64) FilterExclude(slice []int64) []int64
- func (s Int64) FilterInclude(slice []int64) []int64
- func (s Int64) Intersect(other Int64) Int64
- func (s Int64) IntersectSlice(other []int64) Int64
- func (s Int64) Union(other Int64) Int64
- func (s Int64) UnionSlice(other []int64) Int64
- type Set
- func (s *Set) Add(vals ...any)
- func (s Set) Contains(vals ...any) bool
- func (s Set) ContainsAny(vals ...any) bool
- func (s *Set) Del(vals ...any)deprecated
- func (s *Set) Delete(vals ...any)
- func (s Set) Diff(other Set) Set
- func (s Set) DiffSlice(other any) Set
- func (s Set) FilterContains(slice any) any
- func (s Set) FilterExclude(slice any) anydeprecated
- func (s Set) FilterInclude(slice any) anydeprecated
- func (s Set) FilterNotContains(slice any) any
- func (s Set) Intersect(other Set) Set
- func (s Set) IntersectSlice(other any) Set
- func (s Set) Iterate(fn func(any))
- func (s Set) Map() map[any]bool
- func (s Set) MarshalJSON() ([]byte, error)
- func (s Set) MarshalYAML() (any, error)
- func (s Set) Size() int
- func (s Set) Slice() []any
- func (s Set) Union(other Set) Set
- func (s Set) UnionSlice(other any) Set
- func (s *Set) UnmarshalJSON(b []byte) error
- func (s *Set) UnmarshalYAML(unmarshal func(any) error) error
- type String
- func (s String) Del(vals ...string)
- func (s String) Diff(other String) String
- func (s String) DiffSlice(other []string) String
- func (s String) FilterExclude(slice []string) []string
- func (s String) FilterInclude(slice []string) []string
- func (s String) Intersect(other String) String
- func (s String) IntersectSlice(other []string) String
- func (s String) Union(other String) String
- func (s String) UnionSlice(other []string) String
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Generic ¶
type Generic[T comparable] struct { // contains filtered or unexported fields }
Generic is a generic set collection. The zero value of Generic is an empty instance ready to use. A zero Generic set value shall not be copied, or it may result incorrect behavior.
func New ¶
func New[T comparable](vals ...T) Generic[T]
New creates a set instance and add the given values into the set.
func NewWithSize ¶
func NewWithSize[T comparable](size int) Generic[T]
NewWithSize creates a set instance with given initial size.
func (*Generic[T]) Add ¶
func (s *Generic[T]) Add(vals ...T)
Add adds the given values into the set.
func (Generic[T]) ContainsAny ¶
ContainsAny returns true if the set contains any of the values.
func (*Generic[T]) Delete ¶
func (s *Generic[T]) Delete(vals ...T)
Delete deletes values from the set.
func (Generic[T]) FilterContains ¶
func (s Generic[T]) FilterContains(slice []T) []T
FilterContains returns a new slice which contains values that present in the provided slice and also present in the set.
func (Generic[T]) FilterNotContains ¶
func (s Generic[T]) FilterNotContains(slice []T) []T
FilterNotContains returns a new slice which contains values that present in the provided slice but don't present in the set.
func (Generic[T]) Intersect ¶
Intersect returns a new set about values which other set also contains.
func (Generic[T]) IntersectSlice ¶
IntersectSlice is similar to Intersect, but takes a slice as parameter.
func (Generic[T]) Iterate ¶
func (s Generic[T]) Iterate(fn func(T))
Iterate iterates the set in no particular order and calls the given function for each set element.
func (Generic[T]) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface, the set will be marshaled as a slice []T.
func (Generic[T]) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler interface of the yaml package, the set will be marshaled as a slice []T.
func (Generic[T]) Slice ¶
func (s Generic[T]) Slice() []T
Slice converts the set into a slice of type []T.
func (Generic[T]) UnionSlice ¶
UnionSlice is similar to Union, but takes a slice as parameter.
func (*Generic[T]) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface, it will unmarshal a slice []T to the set.
type Int ¶
Int is an int set collection. The zero value of Int is an empty instance ready to use. A zero Int value shall not be copied, or it may result incorrect behavior.
This type is mainly for compatibility with old code, the generic implementation Generic[int] is favored over this.
func NewIntWithSize ¶
NewIntWithSize creates an Int set instance with given initial size.
func (Int) FilterExclude ¶
func (Int) FilterInclude ¶
func (Int) IntersectSlice ¶
func (Int) UnionSlice ¶
type Int32 ¶
Int32 is an int32 set collection. The zero value of Int32 is an empty instance ready to use. A zero Int32 value shall not be copied, or it may result incorrect behavior.
This type is mainly for compatibility with old code, the generic implementation Generic[int32] is favored over this.
func NewInt32WithSize ¶
NewInt32WithSize creates an Int32 set instance with given initial size.
func (Int32) FilterExclude ¶
func (Int32) FilterInclude ¶
func (Int32) IntersectSlice ¶
func (Int32) UnionSlice ¶
type Int64 ¶
Int64 is an int64 set collection. The zero value of Int64 is an empty instance ready to use. A zero Int64 value shall not be copied, or it may result incorrect behavior.
This type is mainly for compatibility with old code, the generic implementation Generic[int64] is favored over this.
func NewInt64WithSize ¶
NewInt64WithSize creates an Int64 set instance with given initial size.
func (Int64) FilterExclude ¶
func (Int64) FilterInclude ¶
func (Int64) IntersectSlice ¶
func (Int64) UnionSlice ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a set collection of any type. The zero value of Set is an empty instance ready to use. A zero Set value shall not be copied, or it may result incorrect behavior.
func NewSet ¶
NewSet creates a Set instance and add the given values into the set. If given only one param which is a slice, the elements of the slice will be added into the set using reflection.
func NewSetWithSize ¶
NewSetWithSize creates a Set instance with given initial size.
func (*Set) Add ¶
Add adds the given values into the set. If given only one param which is a slice, the elements of the slice will be added into the set using reflection.
func (Set) ContainsAny ¶
ContainsAny returns true if the set contains any of the values.
func (Set) DiffSlice ¶
DiffSlice is similar to Diff, but takes a slice as parameter. Param other must be a slice of []any or slice of the concrete element type, else it panics.
func (Set) FilterContains ¶
FilterContains returns a new slice which contains values that present in the provided slice and also present in the Set. Param slice must be a slice of []any or slice of the concrete element type, else it panics.
func (Set) FilterExclude
deprecated
FilterExclude returns a new slice which contains values that present in the provided slice but don't present in the Set. Param slice must be a slice of []any or slice of the concrete element type, else it panics.
Deprecated: FilterExclude has been renamed to FilterNotContains.
func (Set) FilterInclude
deprecated
FilterInclude returns a new slice which contains values that present in the provided slice and also present in the Set. Param slice must be a slice of []any or slice of the concrete element type, else it panics.
Deprecated: FilterInclude has been renamed to FilterContains.
func (Set) FilterNotContains ¶
FilterNotContains returns a new slice which contains values that present in the provided slice but don't present in the Set. Param slice must be a slice of []any or slice of the concrete element type, else it panics.
func (Set) IntersectSlice ¶
IntersectSlice is similar to Intersect, but takes a slice as parameter. Param other must be a slice of []any or slice of the concrete element type, else it panics.
func (Set) Iterate ¶
Iterate iterates the set in no particular order and calls the given function for each set element.
func (Set) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface, the set will be marshaled as a slice []any.
func (Set) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler interface of the yaml package, the set will be marshaled as a slice []any.
func (Set) UnionSlice ¶
UnionSlice is similar to Union, but takes a slice as parameter. Param other must be a slice of []any or slice of the concrete element type, else it panics.
func (*Set) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface, it will unmarshal a slice []any to the set.
type String ¶
String is a string set collection. The zero value of String is an empty instance ready to use. A zero String value shall not be copied, or it may result incorrect behavior.
This type is mainly for compatibility with old code, the generic implementation Generic[string] is favored over this.
func NewStringWithSize ¶
NewStringWithSize creates a String set instance with given initial size.