Skip to content

Repository files navigation

nestedmap Go Reference

nestedmap is a nested map for Go.

nestedmap prevents panic: assignment to entry in nil map and we don't have to worry about map initialization.

requirement

nestedmap requires Go 1.18+.

how to use

install

$ go get github.com/arkuchy/nestedmap

usage

package main
import (
"fmt""github.com/arkuchy/nestedmap"
)
funcmain() {
// Initialize nestedmap with type argument// map[string]map[int]boolnm:=nestedmap.NewNestedMap[string, int, bool]()
// Set valuenm.Set("gopher", 117, false)
nm.Set("gopher", 118, true)
// map[gopher:map[117:false 118:true]]]// Get outer value. The type is map[int]boolifm, ok:=nm.GetOuter("gopher"); ok {
fmt.Println(m) // output: map[117:true 118:true]
}
// Get inner value. The type is boolifv, ok:=nm.GetInner("gopher", 118); ok {
fmt.Println(v) // output: true
}
// When we try to get non-existing data, ok is falseifv, ok:=nm.GetInner("gooopher", 118); ok {
fmt.Println(v) // not called
}
}

About

nested map for Go

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages