maps

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: BSD-3-Clause Imports: 0 Imported by: 1

README

maps

Some functions for working with Go maps.

Documentation: https://pkg.go.dev/github.com/andreas19/maps

Documentation

Overview

Package maps provides some functions for working with Go maps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

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

Clear removes all items from a map.

func Clone

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

Clone clones a map.

func Contains

func Contains[K comparable, V any](m map[K]V, key K) bool

Contains returns true if key is in map m.

func Equal

func Equal[K, V comparable](m1, m2 map[K]V) bool

Equal returns true if the two maps are equal (containing the same keys with the same values).

func EqualFunc

func EqualFunc[K comparable, V any](m1, m2 map[K]V, equal func(v1, v2 V) bool) bool

EqualFunc returns true if the two maps are equal using a function to compare values.

func FromItems

func FromItems[K comparable, V any](items []Item[K, V]) map[K]V

FromItems makes a map from a slice of Item objects.

func FromSlices

func FromSlices[K comparable, V any](keys []K, values []V) map[K]V

FromSlices makes a map from two slices. If the keys slice is longer then the values slice, the surplus keys will have the null value of type T as their value. Surplus values will be ignored.

func Get

func Get[K comparable, V any](m map[K]V, key K, dflt V) V

Get returns the value for key from map m or a default value.

func Keys

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

Keys returns a slice with all keys from map m.

func KeysForValue

func KeysForValue[K, V comparable](m map[K]V, value V) []K

KeysForValue returns a slice with keys which have the given value.

func KeysForValueFunc

func KeysForValueFunc[K, V comparable](m map[K]V, value V, equal func(v1, v2 V) bool) []K

KeysForValueFunc returns a slice with keys which have the given value using a function to compare values.

func Update

func Update[K comparable, V any](m1, m2 map[K]V)

Update updates a map with items from another map.

func Values

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

Values returns a slice with all values from map m.

Types

type Item

type Item[K comparable, V any] struct {
	Key   K
	Value V
}

Type Item represents a key-value pair.

func Items

func Items[K comparable, V any](m map[K]V) []Item[K, V]

Items returns a slice of Item objects for the given map.

Jump to

Keyboard shortcuts

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