Documentation
¶
Index ¶
- func Delete[T any](m *TypedMap, key TypedKey[T])
- func Get[T any](m ReadableTypedMap, key TypedKey[T]) (T, bool)
- func GetOrDefault[T any](m ReadableTypedMap, key TypedKey[T], defaultValue T) T
- func GetOrSetFunc[T any](m *TypedMap, key TypedKey[T], genFunc func() T) T
- func Set[T any](m *TypedMap, key TypedKey[T], value T)
- type ReadableTypedMap
- type ReadonlyTypedMap
- type TypedKey
- type TypedMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
Delete removes the value associated with the given key. The key's type parameter indicates which type of value to delete.
func Get ¶
func Get[T any](m ReadableTypedMap, key TypedKey[T]) (T, bool)
Get retrieves a value in a type-safe way. Works with both TypedMap and ReadonlyTypedMap.
func GetOrDefault ¶
func GetOrDefault[T any](m ReadableTypedMap, key TypedKey[T], defaultValue T) T
GetOrDefault retrieves a value or returns the default if not found. Works with both TypedMap and ReadonlyTypedMap.
func GetOrSetFunc ¶
GetOrSetFunc retrieves a value and set the value with the result of the given function if not found.
Types ¶
type ReadableTypedMap ¶
type ReadableTypedMap interface {
// contains filtered or unexported methods
}
ReadableTypedMap is an interface for read operations on typed maps. Both TypedMap and ReadonlyTypedMap implement this interface.
type ReadonlyTypedMap ¶
type ReadonlyTypedMap struct {
// contains filtered or unexported fields
}
ReadonlyTypedMap is a read-only view of a TypedMap.
func (*ReadonlyTypedMap) Clone ¶
func (m *ReadonlyTypedMap) Clone() *ReadonlyTypedMap
Clone creates a new ReadonlyTypedMap with the same contents.
func (*ReadonlyTypedMap) Keys ¶
func (m *ReadonlyTypedMap) Keys() []string
Keys returns all keys in the map as a slice of strings
type TypedKey ¶
type TypedKey[T any] struct { // contains filtered or unexported fields }
TypedKey represents a key with associated type information. The type parameter T indicates what type this key will retrieve.
func NewTypedKey ¶
NewTypedKey creates a new typed key with the given string identifier.
type TypedMap ¶
type TypedMap struct {
// contains filtered or unexported fields
}
TypedMap is a thread-safe map with type-safe operations.
func (*TypedMap) AsReadonly ¶
func (m *TypedMap) AsReadonly() *ReadonlyTypedMap
AsReadonly returns a read-only view of this map.