We've already got generic type-safe slices and maps since Go 1.21, but we want more.
Sub packages provided here share some common patterns:
- no third-party dependencies (except
golang.org/x
packages), - provides alternative constructors for custom types:
- provides
Reverse
methods for ordered sequences, to be used for reversion ordinary - (most) methods could be chained:
sets.New[float64](1,2,3,4,5).Union(sets.New(1,3,5,7,9)).Unset(1).Map(math.Sqrt)
heaps.New[float64]().Reverse().Push(9).Push(1)
- provides
Clone
methods to get a deep copy of the original one, - provides experimental Iterators, see below for usage and development guides.
- set
- heap
- list
- skip list
- ring
- stack?
- queue?
- chainable maps?
- chainable slices?
go get github.com/houz42/abstract@latest
If you want to try the experimental iterator and range func features,
set environment variable GOEXPERIMENT=rangefunc
before running any go
command:
GOEXPERIMENT=rangefunc go install my/program
GOEXPERIMENT=rangefunc go build my/program
GOEXPERIMENT=rangefunc go test my/program
GOEXPERIMENT=rangefunc go test my/program -bench=.
See the range func wiki for more details.
To develop with the experimental features, follow the gist to install gotip and least gopls and configure vs code.