https://github.com/spenserblack/go-defaultmap
A map with default values
https://github.com/spenserblack/go-defaultmap
default defaultmap generics go golang map
Last synced: 5 months ago
JSON representation
A map with default values
- Host: GitHub
- URL: https://github.com/spenserblack/go-defaultmap
- Owner: spenserblack
- License: mit
- Created: 2022-06-08T18:03:38.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-08T19:42:38.000Z (over 3 years ago)
- Last Synced: 2025-09-09T01:32:46.970Z (5 months ago)
- Topics: default, defaultmap, generics, go, golang, map
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# defaultmap
[](https://pkg.go.dev/github.com/spenserblack/go-defaultmap)
[](https://github.com/spenserblack/go-defaultmap/actions/workflows/ci.yml)
[](https://codecov.io/gh/spenserblack/go-defaultmap)
A map that supports default values.
## Basic Example
```go
import (
"fmt"
"github.com/spenserblack/go-defaultmap"
)
m := defaultmap.NewMap[string](func() string { return "I'm the default!" })
m.Insert("exists", "Hello, World!")
fmt.Println(m.Get("exists")) // Hello, World!
fmt.Println(m.Get("doesn't exist")) // I'm the default!
fmt.Println(m.GetOr("also doesn't exist", "I'm a one-time default!")) // I'm a one-time default!
```