maputil

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package maputil provides utilities for working with maps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortedKeys

func SortedKeys[K cmp.Ordered, V any](m map[K]V) []K

SortedKeys returns the keys of a map sorted in ascending order.

func SortedNames added in v0.4.5

func SortedNames[T any](items []T, getName func(T) string) []string

SortedNames extracts unique names from a slice using the provided getter function and returns them sorted in ascending order.

Types

type Set added in v0.2.0

type Set[T comparable] map[T]struct{}

Set is a generic set type that serializes to/from JSON arrays.

func NewSet added in v0.2.0

func NewSet[T comparable](values ...T) Set[T]

NewSet creates a Set from values.

func (Set[T]) Add added in v0.2.0

func (s Set[T]) Add(value T)

Add adds a value to the set.

func (Set[T]) Contains added in v0.2.0

func (s Set[T]) Contains(value T) bool

Contains returns true if the value is in the set.

func (Set[T]) Len added in v0.2.0

func (s Set[T]) Len() int

Len returns the number of elements in the set.

func (Set[T]) MarshalJSON added in v0.2.0

func (s Set[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Set[T]) Remove added in v0.2.0

func (s Set[T]) Remove(value T)

Remove removes a value from the set.

func (*Set[T]) UnmarshalJSON added in v0.2.0

func (s *Set[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (Set[T]) Values added in v0.2.0

func (s Set[T]) Values() []T

Values returns all values as a slice.

Jump to

Keyboard shortcuts

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