Skip to content

Foxcapades/gomp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Ordered Maps

Build Status Latest Tag gomp badge

Typed ordered maps for go.

Generated for all of Go’s base types. Generator included for adding custom types.

Example
func main() {
  // Create a new ordered map of interface->interface presized to 10
  foo := omap.NewMapAny(10)

  // Puts hi->bye into the map
  foo.Put("hi", "bye").
    // Puts nothing into the map (because val is nil)
    PutIfNotNil("teeth", nil).
    // Appends fire->water to the map because key fire does not yet exist
    ReplaceOrPut("fire", "water").
    // Replaces the value at key "hi" with "hello"
    ReplaceIfExists("hi", "hello").
    // Iterates over all entries in the map with the given func
    ForEach(func(k, v interface{}) {
      fmt.Println(k, v)
    })

  enc := json.NewEncoder(os.Stdout)
  enc.SetIndent("", "  ")
  _ = enc.Encode(foo)
}
Output
$ go run example/main.go
hi hello
fire water
[
  {
    "key": "hi",
    "value": "hello"
  },
  {
    "key": "fire",
    "value": "water"
  }
]

Generator

Generator Usage
./gomp-gen path/to/config.yml

About

Gomp?

Gomp is a Norwegian word for Muggle.