Documentation ¶
Index ¶
- type Set
- func Empty[A comparable]() *Set[A]
- func FromSlice[A comparable](elems []A) *Set[A]
- func FromSliceBy[A any, K comparable](projection func(A) K, elems []A) *Set[A]
- func NewSet[A comparable](elems iterable.Iterable[A]) *Set[A]
- func NewSetBy[A any, K comparable](projection func(A) K, initialElements iterable.Iterable[A]) *Set[A]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[A any] struct { Add func(A) bool Delete func(A) bool Contains func(A) bool Len func() int ToSlice func() []A Union func(*Set[A]) *Set[A] Intersect func(*Set[A]) *Set[A] Difference func(*Set[A]) *Set[A] Iterator func() iterable.Iterator[A] }
func Empty ¶ added in v0.2.3
func Empty[A comparable]() *Set[A]
func FromSlice ¶ added in v0.2.1
func FromSlice[A comparable](elems []A) *Set[A]
func FromSliceBy ¶ added in v0.2.1
func FromSliceBy[A any, K comparable](projection func(A) K, elems []A) *Set[A]
func NewSetBy ¶
func NewSetBy[A any, K comparable](projection func(A) K, initialElements iterable.Iterable[A]) *Set[A]
NewSetBy allows creation of a set from an element type which isn't comparable.
Why is 'comparable' required? Because this set implementation uses a map. Unfortunately, it's not possible to add implementations of user-defined types for comparable. This uses a projection function to create a `comparable` key. VERY VERY VERY IMPORTANT NOTES about the projection function: - it should be a pure function (no side effects) - it should make intuitive sense - don't mix sets which use different projections -- the results will be unpredictable and won't make sense
Click to show internal directories.
Click to hide internal directories.