Generic list, map, and set definitions with common utility methods.
go get github.com/cholland1989/go-collection
This library supports version 1.20 and later of Go.
import "github.com/cholland1989/go-collection/pkg/collection"
Lists can be used interchangeably with slices of the same type, and support
all of the same built-in functions such as make
, append
, and range
:
values := make(collection.List[int], 0)
values.AddAll(0, 1, 0, 1)
for index, value := range values {
fmt.Println(index, value)
}
Maps can be used interchangeably with maps of the same type, and support all
of the same built-in functions such as make
, delete
, and range
:
values := make(collection.Map[int, int])
values.Put(0, 1)
values.Put(1, 0)
for key, value := range values {
fmt.Println(key, value)
}
Sets can be used interchangeably with a map of empty structs, and support all
of the same built-in functions such as make
, delete
, and range
:
values := make(collection.Set[int])
values.AddAll(0, 1, 0, 1)
for value := range values {
fmt.Println(value)
}
See the documentation for more details.
Released under the MIT License.