https://github.com/devnw/gen
gen is a generic general use Go functions library with the intention of replacing duplicated code where the same functionality is needed across multiple types, and provides a common interface for the functionality. The library is designed to be used in a wide variety of projects and is designed to be easy to use.
https://github.com/devnw/gen
data-structures generic-collections generic-functions generic-library generic-programming generic-types generics go golang google-go gophers library software-engineering struct structs structures
Last synced: 4 days ago
JSON representation
gen is a generic general use Go functions library with the intention of replacing duplicated code where the same functionality is needed across multiple types, and provides a common interface for the functionality. The library is designed to be used in a wide variety of projects and is designed to be easy to use.
- Host: GitHub
- URL: https://github.com/devnw/gen
- Owner: devnw
- License: apache-2.0
- Created: 2021-12-18T12:57:38.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-11T00:49:34.000Z (9 months ago)
- Last Synced: 2026-01-12T00:47:41.382Z (5 days ago)
- Topics: data-structures, generic-collections, generic-functions, generic-library, generic-programming, generic-types, generics, go, golang, google-go, gophers, library, software-engineering, struct, structs, structures
- Language: Go
- Homepage:
- Size: 10.4 MB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# `gen` - Generic Go Utility Library
[](https://github.com/devnw/gen/actions)
[](https://goreportcard.com/report/go.devnw.com/gen)
[](https://pkg.go.dev/go.devnw.com/gen)
[](https://opensource.org/licenses/Apache-2.0)
[](http://makeapullrequest.com)
`gen` is a generic general use Go functions library with the intention of
replacing duplicated code where the same functionality is needed across multiple
types, and provides a common interface for the functionality.
The library is designed to be used in a wide variety of projects and is
designed to be easy to use.
## Installation
```bash
go get -u go.devnw.com/gen@latest
```
## Import
Example:
```go
import "go.devnw.com/gen"
func main() {
// ...
m := gen.Map[string, string]{
"foo": "bar",
"bar": "baz",
}
// Get a slice of map keys
keys := m.Keys()
// ...
slice1 := []string{"foo", "bar"}
slice2 := []string{"floob", "bar"}
// Call the Unique method without the `gen` prefix.
unique := gen.Unique(slice1, slice2)
existingmap := map[string]int{
"foo": 1223,
"bar": 111,
}
// Cast to the generic Map
m := gen.Map[string, int](existingmap)
keys = m.Keys()
values := m.Values()
// ...
existingSlice := []string{"foo", "bar", "baz"}
// Cast to the generic Slice
s := gen.Slice[string](existingSlice)
// Convert slice to map
m := s.Map()
}
```
## Benchmarks
To execute the benchmarks, run the following command:
```bash
go test -bench=. ./...
```
To view benchmarks over time for the `main` branch of the repository they can
be seen on our [Benchmark Report Card].
[Benchmark Report Card]: https://devnw.github.io/gen/dev/bench/