mapx

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: 0BSD Imports: 4 Imported by: 0

README

mapX

License Coverage GitHub Workflow Status Go Report Card Go PKG

Map functions to help compare and merge of maps.

go get github.com/rakunlabs/mapx

Usage

Options:

  • mapx.WithWeakType(true/false) to enable/disable weak type comparison. Default is true.
  • mapx.WithCaseInsensitive(true/false) to enable/disable case insensitive key comparison. Default is false.
testMap := map[string]any{
    "abc": 1,
    "def": map[string]any{
        "abc": int64(1),
        "xyz": float32(2),
    },
}

subMap := map[string]any{
    "abc": 1,
    "def": map[string]any{
        "abc": "1",
    },
}

err := mapx.IsMapSubset(testMap, subMap, mapx.WithWeakType(true))
// this will return nil error because 1 == "1" with weak type comparison

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(m map[string]any, key []string) (any, bool)

Get returns the value of the key in the map.

If the key does not exist, the second return value is false.

Example:

m := map[string]any{
	"def": map[string]any{
		"abc": 1,
		"xyz": 2,
	},
}
v, ok := Get(m, []string{"def", "abc"})
// v = 1, ok = true

func IsMapSubset

func IsMapSubset(mapSet, mapSubset map[string]any, opts ...OptionCompare) error

IsMapSubset returns true if mapSubset is a subset of mapSet otherwise false.

func IsSliceContains

func IsSliceContains(slice []any, value any, opts ...OptionCompare) error

IsSliceContains returns true if slice contains value otherwise false.

func IsSliceSubset

func IsSliceSubset(sliceSet []any, sliceSubset []any, opts ...OptionCompare) error

IsSliceSubset returns true if sliceSubset is a subset of sliceSet otherwise false.

func IsSubset

func IsSubset(set, subset any, opts ...OptionCompare) error

func Merge

func Merge(value map[string]any, to map[string]any) map[string]any

func MergeAny

func MergeAny(value any, to any) any

Types

type OptionCompare

type OptionCompare func(*optionCompare)

func WithCaseInsensitive

func WithCaseInsensitive(v bool) OptionCompare

func WithWeakType

func WithWeakType(v bool) OptionCompare

Jump to

Keyboard shortcuts

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