Git Product home page Git Product logo

syncmap2yyle's Introduction

syncmap2yyle

Generics sync map

泛型的 sync map

Sync map generics

Sync map 范型版

This toolkit provides a comprehensive encapsulation of the methods in sync.Map, ensuring that both the parameters and return values remain unchanged. As a result, these methods can be seamlessly substituted and utilized. Moreover, the presence of generics in this toolkit eliminates the need for any conversions to interface{}, enhancing its efficiency and convenience.

该工具包100%封装sync.Map的方法且方法的参数和返回值都不变,因此可以直接替换使用,但由于具有泛型而能避免interface{}的转换

Due to the lengthy name of this account and the cumbersome package name, the code has been migrated to a new location. Going forward, the focus will be on maintaining the new package:

由于该github的名字冗长且该工具包名也冗长,因此已经将代码转移到新的地方,以后优先维护新包:

go get github.com/yyle88/syncmap

Despite the migration of the code to a new repository, it's worth noting that the old repository is still functional and available for use. While the focus will be on maintaining the new package, the option to continue using the old repository remains open:

当然旧的依然可以使用:

go get github.com/yangyile1990/syncmap2yyle

demo1:

package main

import (
	"fmt"

	"github.com/yangyile1990/syncmap2yyle"
)

func main() {
	mp := syncmap2yyle.NewMap[int, string]()

	mp.Store(1, "a")
	mp.Store(2, "b")
	mp.Store(3, "c")

	mp.Range(func(key int, value string) bool {
		fmt.Println(key, value)
		return true
	})
}

demo2:

package main

import (
	"fmt"

	"github.com/yangyile1990/syncmap2yyle"
)

type Person struct {
	Name     string
	Age      int
	HomePage string
}

func main() {
	mp := syncmap2yyle.NewMap[int, *Person]()

	mp.Store(1, &Person{
		Name:     "Kratos",
		HomePage: "https://go-kratos.dev/",
	})
	mp.Store(2, &Person{
		Name: "YangYiLe",
		Age:  18,
	})
	mp.Store(3, &Person{
		Name: "DiLiReBa",
		Age:  18,
	})

	mp.Delete(3)

	mp.Range(func(key int, value *Person) bool {
		fmt.Println(key, value.Name, value.Age, value.HomePage)
		return true
	})
}

syncmap2yyle's People

Contributors

yangyile1990 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.