Help us shape the future of Go! Take the 2026 Go Developer Survey

maputil

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 6 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[M ~map[K]V, K cmp.Ordered, V any](m M) iter.Seq[K]

SortedKeys returns an iterator over the keys of m in ascending order. The ~map[K]V constraint also accepts defined map types such as Set.

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