/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.

Primary LanguageGoApache License 2.0Apache-2.0

gen - Generic Go Utility Library

Build & Test Action Status Go Report Card Go Reference License: Apache 2.0 PRs Welcome

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

go get -u go.devnw.com/gen@latest

Import

Example:

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:

go test -bench=. ./...

To view benchmarks over time for the main branch of the repository they can be seen on our Benchmark Report Card.