Skip to content

muir/list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

list - golang generics for list manipulation

GoDoc unit tests report card codecov

Install:

go get github.com/muir/list

This package is a collection of generic functions to manipulate slices.

Splice/Replace

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.

Copy

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.

Code stability

This is brand new, but has 100% test coverage and is unlikely to be modifed except to add new functions.

Contributions

I would be happy to collect other list functions in this repo. Open a pull request. Include tests that maintain the current 100% coverage.

About

golang generics for list manipulation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages