maputils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package maputils defines utilities for working with maps; before using this package, consider using the package "maps".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertValuesNotNil

func AssertValuesNotNil[M ~map[K]V, K comparable, V any](source M) error

AssertValuesNotNil returns an error if the given map contains a key with a nil value, otherwise nil.

func DeleteKeys

func DeleteKeys[M ~map[K]V, K comparable, V any](source M, keys ...K)

DeleteKeys deletes the given keys from the given map.

func Fold

func Fold[M ~map[K]V, K comparable, V, T any](
	folder folders.Folder[T, K],
	initial T,
	source M,
) result.Result[T]

Fold passes a slice of the keys of the given map and the given initial value and folder to sliceutils.Fold.

func FoldResult

func FoldResult[M ~map[K]V, K comparable, V, T any](
	folder folders.Folder[T, K],
	initial T,
	source result.Result[M],
) result.Result[T]

FoldResult calls Fold on the map encapsulated in the given result. If the given result encapsulates an error, that error is returned in a result of the return type.

func Get

func Get[M ~map[K]V, K comparable, V any](source M, key K) maybe.Maybe[V]

Get calls the two value map index and converts to a Maybe.

func LenAll

func LenAll[M ~map[K]V, K comparable, V any](sources ...M) int

LenAll returns the accumulated lengths of the values of the given maps.

func Map

func Map[M ~map[K]V, K comparable, V, T any](
	mapper result.FlatMapper[K, T],
	source M,
) result.Result[map[K]T]

Map the given source map of type, using the given mapper, into a new map. The keys of the source map are used to store the mapped values in the new map. If a filter is specified, only values whose keys match the filter are mapped into the new map. Returns the new map containing the mapped values, never nil; additionally, an error is returned if either the mapper or the filter fails.

func MapResult

func MapResult[M ~map[K]V, K comparable, V, T any](
	source result.Result[M],
	mapper result.FlatMapper[K, T],
) result.Result[map[K]T]

MapResult calls Map on the map encapsulated in the given result. If the given result encapsulates an error, that error is returned in a result of the return type.

func Merge

func Merge[M ~map[K]V, K comparable, V any](sources ...M) M

Merge returns a map containing all the keys and values of the given maps; when duplicate keys exist the value of the "last-man-in" wins; never nil.

func Select

func Select[M ~map[K]V, K comparable, V any](
	source M,
	filter filters.Filter[K],
) result.Result[M]

Select returns a map containing the values for the keys from the given map that match the given filter; never nil.

func ToAnyMap

func ToAnyMap(value any) map[any]any

ToAnyMap attempts to type-convert the given value to an "any map", otherwise returns a "nil map".

func ToBool

func ToBool[M ~map[string]any](
	source M,
	key string,
) (bool, error)

ToBool returns the bool value for the given key in the given map. If the value is not a bool an error is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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