Package Usage: go: github.com/benbjohnson/immutable
Package immutable provides immutable collection types.
Immutable collections provide an efficient, safe way to share collections
of data while minimizing locks. The collections in this package provide
List, Map, and SortedMap implementations. These act similarly to slices
and maps, respectively, except that altering a collection returns a new
copy of the collection with that change.
Because collections are unable to change, they are safe for multiple
goroutines to read from at the same time without a mutex. However, these
types of collections come with increased CPU & memory usage as compared
with Go's built-in collection types so please evaluate for your specific
use.
The List type provides an API similar to Go slices. They allow appending,
prepending, and updating of elements. Elements can also be fetched by index
or iterated over using a ListIterator.
The Map & SortedMap types provide an API similar to Go maps. They allow
values to be assigned to unique keys and allow for the deletion of keys.
Values can be fetched by key and key/value pairs can be iterated over using
the appropriate iterator type. Both map types provide the same API. The
SortedMap, however, provides iteration over sorted keys while the Map
provides iteration over unsorted keys. Maps improved performance and memory
usage as compared to SortedMaps.
Map types require the use of a Hasher implementation to calculate hashes for
their keys and check for key equality. SortedMaps require the use of a
Comparer implementation to sort keys in the map.
These collection types automatically provide built-in hasher and comparers
for int, string, and byte slice keys. If you are using one of these key types
then simply pass a nil into the constructor. Otherwise you will need to
implement a custom Hasher or Comparer type. Please see the provided
implementations for reference.
9 versions
Latest release: over 2 years ago
307 dependent packages
View more package details: https://packages.ecosystem.code.gouv.fr/registries/proxy.golang.org/packages/github.com/benbjohnson/immutable