Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T comparable] slice.Slice[T]
Set is a collection of unique values
Example (SliceMethods) ¶
// Create a Set set := New([]int{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}) // Cast the set to a slice slice := slice.Slice[int](set) slice.ForEach(func(v, i int) { fmt.Println(v) }) mapped := slice.Map(func(v, i int) int { return v * 2 }) fmt.Println(mapped)
Output: 1 2 3 4 [2 4 6 8]
func New ¶
func New[T comparable](slice []T) Set[T]
New creates a new set from a slice
Example ¶
// Create a slice slice := []int{1, 2, 2, 3, 3, 3, 4, 4, 4, 4} // Create a set from the slice set := New(slice) // Print the set fmt.Println(set)
Output: [1 2 3 4]
func (*Set[T]) Add ¶
Adds another element to the Set
Example ¶
// Create a Set set := New([]int{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}) set.Add(5) set.Add(7) // Print the set fmt.Println(set)
Output: [1 2 3 4 5 7]
func (*Set[T]) Clear ¶
func (s *Set[T]) Clear()
Clears the entire Set
Example ¶
// Create a Set set := New([]int{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}) // Clear the set set.Clear() // Print the set fmt.Println(set)
Output: []
func (*Set[T]) Delete ¶
Delete an element from the Set
Example ¶
// Create a Set set := New([]int{1, 2, 2, 3, 3, 3, 4, 4, 4, 4}) set.Delete(2) set.Delete(4) // Print the set fmt.Println(set)
Output: [1 3]
func (*Set[T]) ForEach ¶
Executes a callback function for each element in the Set
Example ¶
// Create a Set set := New([]int{1, 2, 3, 4}) // Print the set set.ForEach(func(v, i int) { fmt.Println(v) })
Output: 1 2 3 4
Click to show internal directories.
Click to hide internal directories.