Documentation ¶
Index ¶
- func Apply[K comparable](in []K, f func(K) K) []K
- func Contains[K comparable](in []K, e K) bool
- func Filter[K comparable](in []K, r ...K) []K
- func Map[K comparable](in []K) map[K]bool
- func Sorted[K constraints.Ordered](l []K) []K
- func SortedFiltered[K constraints.Ordered](l []K, want func(K) bool) []K
- func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K
- type Set
- func (s *Set[K]) Add(elems ...K) bool
- func (s Set[K]) Choose(f func(K) bool) (K, bool)
- func (s Set[K]) Clone() Set[K]
- func (s Set[K]) Contains(e K) bool
- func (s Set[K]) Count(f func(K) bool) int
- func (s Set[K]) Difference(s2 Set[K]) Set[K]
- func (s Set[K]) Discard(elems ...K) bool
- func (s Set[K]) Each(f func(K))
- func (s Set[K]) Elements() []K
- func (s Set[K]) Empty() bool
- func (s Set[K]) Equals(s2 Set[K]) bool
- func (s Set[K]) IsSubset(s2 Set[K]) bool
- func (s Set[K]) Len() int
- func (s Set[K]) Map(f func(K) K) Set[K]
- func (s Set[K]) Partition(f func(K) bool) (Set[K], Set[K])
- func (s Set[K]) Remove(s2 Set[K]) bool
- func (s Set[K]) Select(f func(K) bool) Set[K]
- func (s Set[K]) String() string
- func (s Set[K]) SymmetricDifference(s2 Set[K]) Set[K]
- func (s Set[K]) Union(s2 Set[K]) Set[K]
- func (s *Set[K]) Update(s2 Set[K]) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶ added in v1.14.2
func Apply[K comparable](in []K, f func(K) K) []K
Apply applies the given function to every element of the slice.
func Contains ¶ added in v1.15.2
func Contains[K comparable](in []K, e K) bool
Contains returns true if e is contained in the input list.
func Filter ¶
func Filter[K comparable](in []K, r ...K) []K
Filter filters all r's from the input list.
func Map ¶
func Map[K comparable](in []K) map[K]bool
Map takes a slice of a given type and create a boolean map with keys of that type.
func Sorted ¶
func Sorted[K constraints.Ordered](l []K) []K
Sorted returns a sorted set of the input.
func SortedFiltered ¶
func SortedFiltered[K constraints.Ordered](l []K, want func(K) bool) []K
SortedFiltered returns a sorted set of the input, filtered by the predicate.
func SortedKeys ¶ added in v1.15.0
func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K
SortedKeys returns the sorted keys of the map.
Types ¶
type Set ¶ added in v1.15.1
type Set[K constraints.Ordered] map[K]bool
Set is a generic set type.
func New ¶ added in v1.15.1
func New[K constraints.Ordered](elems ...K) Set[K]
New initializes a new Set with the given elements.
func (Set[K]) Contains ¶ added in v1.15.3
Contains returs true if the set contains the presented element.
func (Set[K]) Count ¶ added in v1.15.1
Count returns the number of elements for which f returns true.
func (Set[K]) Difference ¶ added in v1.15.3
Difference returns the set difference. That is all the things that are in s but not in s2. A \ B.
func (Set[K]) Each ¶ added in v1.15.1
func (s Set[K]) Each(f func(K))
Each applies the function f to all it's elements.
func (Set[K]) Elements ¶ added in v1.15.1
func (s Set[K]) Elements() []K
Elements returns the elements of the set in sorted order.
func (Set[K]) Equals ¶ added in v1.15.1
Equals returns true if s and s2 contain exactly the same elements.
func (Set[K]) IsSubset ¶ added in v1.15.1
IsSubset returns true if all elements of s are contained in s2.
func (Set[K]) Map ¶ added in v1.15.1
Map returns a new set by applied the function f to all it's elements.
func (Set[K]) Partition ¶ added in v1.15.1
Partition returns two new sets: the first contains all the elements for which f returns true. The seconds the others.
func (Set[K]) Select ¶ added in v1.15.1
Select returns a new set with all the elements for that f returns true.
func (Set[K]) SymmetricDifference ¶ added in v1.15.3
SymmetricDifference returns the symmetric difference. That is all the things that are in s or s2 but not in both. A Δ B.