typedmap

package
v0.51.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete[T any](m *TypedMap, key TypedKey[T])

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

func GetOrSetFunc[T any](m *TypedMap, key TypedKey[T], genFunc func() T) T

GetOrSetFunc retrieves a value and set the value with the result of the given function if not found.

func Set

func Set[T any](m *TypedMap, key TypedKey[T], value T)

Set stores a value. The key's type parameter must match the value's type.

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

func NewTypedKey[T any](key string) TypedKey[T]

NewTypedKey creates a new typed key with the given string identifier.

func (TypedKey[T]) Key

func (k TypedKey[T]) Key() string

Key returns the string identifier of this key.

type TypedMap

type TypedMap struct {
	// contains filtered or unexported fields
}

TypedMap is a thread-safe map with type-safe operations.

func NewTypedMap

func NewTypedMap() *TypedMap

NewTypedMap creates a new empty TypedMap.

func (*TypedMap) AsReadonly

func (m *TypedMap) AsReadonly() *ReadonlyTypedMap

AsReadonly returns a read-only view of this map.

func (*TypedMap) Clone

func (m *TypedMap) Clone() *TypedMap

Clone creates a new TypedMap with the same contents.

func (*TypedMap) Keys

func (m *TypedMap) Keys() []string

Keys returns all keys in the map as a slice of strings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL