set

package
v1.15.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

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]) Add added in v1.15.1

func (s *Set[K]) Add(elems ...K) bool

Add adds the given elements to the set.

func (Set[K]) Choose added in v1.15.1

func (s Set[K]) Choose(f func(K) bool) (K, bool)

Choose returns the first element for which f returns true.

func (Set[K]) Clone added in v1.15.1

func (s Set[K]) Clone() Set[K]

Clone creates a copy of the set.

func (Set[K]) Contains added in v1.15.3

func (s Set[K]) Contains(e K) bool

Contains returs true if the set contains the presented element.

func (Set[K]) Count added in v1.15.1

func (s Set[K]) Count(f func(K) bool) int

Count returns the number of elements for which f returns true.

func (Set[K]) Difference added in v1.15.3

func (s Set[K]) Difference(s2 Set[K]) Set[K]

Difference returns the set difference. That is all the things that are in s but not in s2. A \ B.

func (Set[K]) Discard added in v1.15.1

func (s Set[K]) Discard(elems ...K) bool

Discard deletes the given elements from the set.

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]) Empty added in v1.15.1

func (s Set[K]) Empty() bool

Empty returns true if the set is empty.

func (Set[K]) Equals added in v1.15.1

func (s Set[K]) Equals(s2 Set[K]) bool

Equals returns true if s and s2 contain exactly the same elements.

func (Set[K]) IsSubset added in v1.15.1

func (s Set[K]) IsSubset(s2 Set[K]) bool

IsSubset returns true if all elements of s are contained in s2.

func (Set[K]) Len added in v1.15.1

func (s Set[K]) Len() int

Len returns the length of the set.

func (Set[K]) Map added in v1.15.1

func (s Set[K]) Map(f func(K) K) Set[K]

Map returns a new set by applied the function f to all it's elements.

func (Set[K]) Partition added in v1.15.1

func (s Set[K]) Partition(f func(K) bool) (Set[K], Set[K])

Partition returns two new sets: the first contains all the elements for which f returns true. The seconds the others.

func (Set[K]) Remove added in v1.15.1

func (s Set[K]) Remove(s2 Set[K]) bool

Remove deletes the given element from the set.

func (Set[K]) Select added in v1.15.1

func (s Set[K]) Select(f func(K) bool) Set[K]

Select returns a new set with all the elements for that f returns true.

func (Set[K]) String added in v1.15.1

func (s Set[K]) String() string

String returns a string representation of the set.

func (Set[K]) SymmetricDifference added in v1.15.3

func (s Set[K]) SymmetricDifference(s2 Set[K]) Set[K]

SymmetricDifference returns the symmetric difference. That is all the things that are in s or s2 but not in both. A Δ B.

func (Set[K]) Union added in v1.15.1

func (s Set[K]) Union(s2 Set[K]) Set[K]

Union returns a new set containing all elements from s and s2. A ∪ B.

func (*Set[K]) Update added in v1.15.1

func (s *Set[K]) Update(s2 Set[K]) bool

Update adds all elements from s2 to the set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL