Install:
go get github.com/muir/list
This package is a collection of generic functions to manipulate slices.
func Replace[E any](dest []E, start int, replace ...E) []E
func ReplaceBeyond[E any](dest []E, start int, replace ...E) []E
func Splice[E any](dest []E, start int, end int, replace ...E) []E
func SpliceBeyond[E any](dest []E, start int, end int, replace ...E) []E
Splice
is the general function of replacing one part of a list/vector/slice with
new elements, growing or shrinking the list as needed.
Replace
is splicing such that the replacements equals the size replaced.
The Beyond
methods allow the replacments to be beyond the len (and cap) of the
original slice. The slice will be extended (and filled) as needed.
func Copy[T any](orig []T) []T
Copy is exactly what you would expect. Given nil
, it returns nil
. It does
not allocate additional space. Copies are shallow.
This is brand new, but has 100% test coverage and is unlikely to be modifed except to add new functions.
I would be happy to collect other list functions in this repo. Open a pull request. Include tests that maintain the current 100% coverage.