Home

Awesome

Go-generics - Generic slice, map, set, iterator, and goroutine utilities for Go

Go Reference Go Report Card Tests Coverage Status Mentioned in Awesome Go

This is go-generics, a collection of typesafe generic utilities for slices, maps, sets, iterators, and goroutine patterns in Go.

Slices

The slices package is useful in three ways:

It also includes combinatorial operations: Permutations, Combinations, and CombinationsWithReplacement.

The slices package is a drop-in replacement for the slices package added to the Go stdlib in Go 1.21. There is one difference: this version of slices allows the index value passed to Insert, Delete, and Replace to be negative for counting backward from the end of the slice.

Maps

The maps package has a few convenience functions for duplicating, inverting, constructing, and iterating over maps, as well as for testing their equality.

The maps package is a drop-in replacement for the maps package added to the Go stdlib in Go 1.21.

Set

The set package implements the usual collection of functions for sets: Intersect, Union, Diff, etc., as well as member functions for adding and removing items, checking for the presence of items, and iterating over items.

Iter

The iter package implements efficient, typesafe iterators that can convert to and from Go slices, maps, and channels, and produce iterators over the values from function calls and goroutines. There is also an iterator over the results of a SQL query; the usual collection of functions on iterators (Filter, Map, Concat, Accum, etc.).

Parallel

The parallel package contains functions for coordinating parallel workers: