• Stars
    star
    17
  • Rank 1,257,181 (Top 25 %)
  • Language
    Go
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

map library using Go generics that offers a standard interface, go routine synchronization, and sorting

Go Reference Build Status Go Report Card codecov

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

package main

import . "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.