Documentation
¶
Overview ¶
Package maputils defines utilities for working with maps; before using this package, consider using the package "maps".
Index ¶
- func AssertValuesNotNil[M ~map[K]V, K comparable, V any](source M) error
- func DeleteKeys[M ~map[K]V, K comparable, V any](source M, keys ...K)
- func Fold[M ~map[K]V, K comparable, V, T any](folder folders.Folder[T, K], initial T, source M) result.Result[T]
- 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]
- func Get[M ~map[K]V, K comparable, V any](source M, key K) maybe.Maybe[V]
- func LenAll[M ~map[K]V, K comparable, V any](sources ...M) int
- func Map[M ~map[K]V, K comparable, V, T any](mapper result.FlatMapper[K, T], source M) result.Result[map[K]T]
- 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]
- func Merge[M ~map[K]V, K comparable, V any](sources ...M) M
- func Select[M ~map[K]V, K comparable, V any](source M, filter filters.Filter[K]) result.Result[M]
- func ToAnyMap(value any) map[any]any
- func ToBool[M ~map[string]any](source M, key string) (bool, error)
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.
Types ¶
This section is empty.