Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goradd/maps
map library using Go generics that offers a standard interface, go routine synchronization, and sorting
https://github.com/goradd/maps
Last synced: 13 days ago
JSON representation
map library using Go generics that offers a standard interface, go routine synchronization, and sorting
- Host: GitHub
- URL: https://github.com/goradd/maps
- Owner: goradd
- License: mit
- Created: 2022-03-20T07:05:16.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-16T18:41:51.000Z (about 1 year ago)
- Last Synced: 2024-07-31T20:46:10.216Z (3 months ago)
- Language: Go
- Size: 58.6 KB
- Stars: 38
- Watchers: 1
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - goradd/maps - Go 1.18+ generic map interface for maps; safe maps; ordered maps; ordered, safe maps; etc. (Data Structures and Algorithms / Maps)
- awesome-go - goradd/maps - Go 1.18+ generic map interface for maps; safe maps; ordered maps; ordered, safe maps; etc. (Data Structures and Algorithms / Maps)
- awesome-go-extra - maps - 03-20T07:05:16Z|2022-03-23T04:40:40Z| (Generators / Maps)
README
[![Go Reference](https://pkg.go.dev/badge/github.com/goradd/maps.svg)](https://pkg.go.dev/github.com/goradd/maps)
![Build Status](https://img.shields.io/github/workflow/status/goradd/maps/Go)
[![Go Report Card](https://goreportcard.com/badge/github.com/goradd/maps)](https://goreportcard.com/report/github.com/goradd/maps)
[![codecov](https://codecov.io/gh/goradd/maps/branch/main/graph/badge.svg?token=LZNNI26H3L)](https://codecov.io/gh/goradd/maps)# maps
maps is a library using Go generics that offers a standard interface for manipulating
different kinds of maps.Using the same interface, you can create and use a standard Go map, a map
that is safe for concurrency and/or a map that lets you order the keys in the map.## Example
```go
package mainimport . "github.com/goradd/maps"
import "fmt"type myMap = Map[string,int] // the equal sign here is critical!
type myStdMap = StdMap[string, int]func main() {
m := new(Map[string, int])
m.Merge(myStdMap{"b":2, "c":3})
m.Set("a",1)sum := 0
m.Range(func(k string, v int) bool {
sum += v
return true
})
fmt.Print(sum)
}```
By simply changing myMap to a SafeMap, you can make the map safe for concurrent use.
Or, you can change myMap to a SliceMap, or a SafeSliceMap to also be able to iterate
the map in the order it was created, similar to a PHP map.