package immutable

import "cuelang.org/go/internal/golangorgx/gopls/util/immutable"

The immutable package defines immutable wrappers around common data structures. These are used for additional type safety inside gopls.

See the "persistent" package for copy-on-write data structures.

Index

Types

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Map is an immutable wrapper around an ordinary Go map.

func MapOf

func MapOf[K comparable, V any](m map[K]V) Map[K, V]

MapOf wraps the given Go map.

The caller must not subsequently mutate the map.

func (Map[K, V]) Len

func (m Map[K, V]) Len() int

Len returns the number of entries in the Map.

func (Map[K, V]) Range

func (m Map[K, V]) Range(f func(k K, v V))

Range calls f for each mapped (key, value) pair. There is no way to break out of the loop. TODO: generalize when Go iterators (#61405) land.

func (Map[K, V]) Value

func (m Map[K, V]) Value(k K) (V, bool)

Value returns the mapped value for k. It is equivalent to the commaok form of an ordinary go map, and returns (zero, false) if the key is not present.

Source Files

immutable.go

Version
v0.12.0 (latest)
Published
Jan 30, 2025
Platform
linux/amd64
Last checked
8 hours ago

Tools for package owners.