go-generics

module
v2.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2023 License: MIT

README

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

Go Reference Go Report Card Tests Coverage Status

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 encapsulates hard-to-remember Go idioms for inserting and removing elements to and from the middle of a slice;
  • It adds the ability to index from the right end of a slice using negative integers (for example, Get(s, -1) is the same as s[len(s)-1]); and
  • It includes Map, Filter, and a few other such functions for processing slice elements with callbacks.

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:

  • Consumers manages a set of N workers consuming a stream of values produced by the caller.
  • Producers manages a set of N workers producing a stream of values consumed by the caller.
  • Values concurrently produces a set of N values.
  • Pool manages access to a pool of concurrent workers.
  • Protect manages concurrent access to a protected data value.

Directories

Path Synopsis
Package iter defines an iterator interface, a collection of concrete iterator types, and some functions for operating on iterators.
Package iter defines an iterator interface, a collection of concrete iterator types, and some functions for operating on iterators.
Package maps contains functions for working with Go maps: duplicating, inverting, constructing, and iterating over them, as well as testing their equality.
Package maps contains functions for working with Go maps: duplicating, inverting, constructing, and iterating over them, as well as testing their equality.
Package parallel contains generic typesafe functions to manage concurrent logic of various kinds.
Package parallel contains generic typesafe functions to manage concurrent logic of various kinds.
Package set contains generic typesafe set operations.
Package set contains generic typesafe set operations.
Package slices contains utility functions for working with slices.
Package slices contains utility functions for working with slices.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL