Documentation
¶
Index ¶
- func DeduplicatePointerless[T comparable](items []T) []T
- func Make[T any](value T) (unique.Handle[string], any, error)
- func SlowUnique[T any](items []T) []T
- func SortMapTuples(items [][2]any, index []string)
- func Unique[T any](items []T) ([]T, error)
- func UniquePointerless[T comparable](items []T) []T
- type SerializableHandle
- type TypedAny
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeduplicatePointerless ¶
func DeduplicatePointerless[T comparable](items []T) []T
func Make ¶
Example ¶
alice := "Alice"
deepHandle, deepPointers, err := Make(&alice)
if err != nil {
fmt.Println("Error:", err)
return
}
otherAlice := "Alice"
otherDeepHandle, otherDeepPointers, err := Make(&otherAlice)
if err != nil {
fmt.Println("Error:", err)
return
}
// Avoid "unused variable" errors. I hope this preserves the pointers through
// garbage collection.
_ = deepPointers
_ = otherDeepPointers
fmt.Println("alice and otherAlice have the same deep handle:", deepHandle == otherDeepHandle)
Output: alice and otherAlice have the same deep handle: true
func SlowUnique ¶
func SlowUnique[T any](items []T) []T
func SortMapTuples ¶
func Unique ¶
Example ¶
alice := "Alice"
otherAlice := "Alice"
alices := []*string{&alice, &otherAlice}
if !reflect.DeepEqual(&alice, &otherAlice) {
fmt.Println("Expected alice and otherAlice to be deep equal")
}
if unique.Make(&alice) == unique.Make(&otherAlice) {
fmt.Println("Expected alice and otherAlice to have different unique handles")
}
uniqueAlices, err := Unique(alices)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Length of uniqueAlices:", len(uniqueAlices))
Output: Length of uniqueAlices: 1
func UniquePointerless ¶
func UniquePointerless[T comparable](items []T) []T
Types ¶
type SerializableHandle ¶
type SerializableHandle[T comparable] struct { Value string // stringified unique.Handle // contains filtered or unexported fields }
func NewSerializableHandle ¶
func NewSerializableHandle[T comparable](value T) SerializableHandle[T]
Click to show internal directories.
Click to hide internal directories.