maps

package
v2.26.3 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: MIT Imports: 1 Imported by: 0

README

Maps

Example

package main

import (
	"fmt"

	"github.com/go-kratos-ecosystem/components/v2/maps"
)

func main() {
	m := maps.M{}

	m.Merge(map[string]any{
		"name":    "Flc",
		"age":     18, //nolint:gomnd
		"sex":     "man",
		"address": "China",
		"phone":   "123456789",
	})

	m.When(true, func(m maps.Maps) maps.Maps {
		return m.Set("first name", "wu").
			Set("last name", "Flc").
			Set("age", 19) //nolint:gomnd
	})

	fmt.Println(m.Maps())

	// output:
	// map[address:China age:19 first name:wu last name:Flc name:Flc phone:123456789 sex:man]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type M added in v2.7.1

type M map[string]any

func (M) All added in v2.7.1

func (m M) All() map[string]any

func (M) Clone added in v2.7.1

func (m M) Clone() M

func (M) Delete added in v2.7.1

func (m M) Delete(k string) M

func (M) Each added in v2.7.1

func (m M) Each(fn func(k string, v any))

func (M) Get added in v2.7.1

func (m M) Get(k string) (any, bool)

func (M) GetX added in v2.7.1

func (m M) GetX(k string) any

func (M) Has added in v2.7.1

func (m M) Has(k string) bool

func (M) Keys added in v2.7.1

func (m M) Keys() []string

func (M) Len added in v2.7.1

func (m M) Len() int

func (M) Map added in v2.7.1

func (m M) Map(fn func(k string, v any) (string, any)) M

func (M) Maps added in v2.7.1

func (m M) Maps() map[string]any

func (M) Merge added in v2.7.1

func (m M) Merge(n M) M

func (M) Set added in v2.7.1

func (m M) Set(k string, v any) M

func (M) Unless added in v2.7.1

func (m M) Unless(guard bool, fn func(maps M) M) M

func (M) Values added in v2.7.1

func (m M) Values() []any

func (M) When added in v2.7.1

func (m M) When(guard bool, fn func(maps M) M) M

Jump to

Keyboard shortcuts

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