Interfaces support any types
Some interfaces defined in the package support only comparable types.
sets.Set
type Set[T comparable] interface {
Add(elements ...T)
Remove(elements ...T)
Contains(elements ...T) bool
containers.Container[T]
// Empty() bool
// Size() int
// Clear()
// Values() []interface{}
// String() string
}
maps.Map
type Map[K comparable, V any] interface {
Put(key K, value V)
Get(key K) (value V, found bool)
Remove(key K)
Keys() []K
containers.Container[V]
// Empty() bool
// Size() int
// Clear()
// Values() []interface{}
// String() string
}
lists.List
type List[T comparable] interface {
Get(index int) (T, bool)
Remove(index int)
Add(values ...T)
Contains(values ...T) bool
Sort(comparator utils.Comparator[T])
Swap(index1, index2 int)
Insert(index int, values ...T)
Set(index int, value T)
containers.Container[T]
// Empty() bool
// Size() int
// Clear()
// Values() []interface{}
// String() string
}
However, some implementations of these interfaces can support any type with a custom comparator.
Is it possible to change the type in the interface from comparable to any? This would allow
implementations to support any type with a custom comparator without breaking backward compatibility.
Hey @sleepymole, what sort of type are you using right now that isn't comparable?
For example, I want to use []byte as a type in Set or as a key in Map. However, []byte isn't comparable.
Hmmm this is interesting. This wouldn't work for map based structures (even the old code would have panicked there), but I suppose it can be relaxed for tree-based ones
Which one do you need, specifically?
Specifically, I want to use treeset and treeset with type []byte.