typedmap

package
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

func ToStringMap added in v0.59.0

func ToStringMap(m ReadableTypedMap) map[string]string

ToStringMap converts all key-value pairs in the map to a string map using fmt.Sprint.

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 Merge added in v0.53.0

func Merge(maps ...ReadableTypedMap) *ReadonlyTypedMap

Merge imports all key-value pairs from multiple ReadableTypedMaps into a new ReadonlyTypedMap.

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