Documentation
¶
Index ¶
- Variables
- type Mapper
- func (mapper *Mapper[T]) Add(values ...T)
- func (mapper *Mapper[T]) All() iter.Seq2[string, T]
- func (mapper *Mapper[T]) Get(key string) (T, error)
- func (mapper *Mapper[T]) HasByKey(key string) bool
- func (mapper *Mapper[T]) HasByValue(value T) bool
- func (mapper *Mapper[T]) Keys() []string
- func (mapper *Mapper[T]) RemoveByKey(key string)
- func (mapper *Mapper[T]) RemoveByValue(value T)
Constants ¶
This section is empty.
Variables ¶
View Source
var (
DoesNotExistError = errors.New("does not exist")
)
Functions ¶
This section is empty.
Types ¶
type Mapper ¶
Mapper provides a bidirectional mapping between string keys and typed values. It is particularly useful for enums, configuration keys, and any scenario where you need to convert between string representations and concrete types.
The type requires T to implement fmt.Stringer, and all keys are stored in lowercase to ensure case-insensitive lookups.
Basic usage:
mapper := NewMapper(StatusPending, StatusActive, StatusClosed)
status, err := mapper.Get("active") // returns StatusActive
exists := mapper.HasByKey("pending") // true
exists := mapper.HasByValue(StatusClosed) // true
The zero value is not ready for use and must be created via NewMapper. All methods are safe for concurrent read-only access, but concurrent writes (Add) require external synchronization.
func (*Mapper[T]) HasByValue ¶
func (*Mapper[T]) RemoveByKey ¶
func (*Mapper[T]) RemoveByValue ¶
func (mapper *Mapper[T]) RemoveByValue(value T)
Click to show internal directories.
Click to hide internal directories.