list

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 1 Imported by: 7

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy added in v1.1.0

func Copy[T any](orig []T) []T

Copy makes a shallow copy of it's input. Given nil, it returns nil.

func Replace

func Replace[E any](dest []E, start int, replace ...E) []E

ReplaceBeyond subsitutes replace into dest starting at start.

Dest may be modified.

Replace will panic if start is beyond the end of dest.

func ReplaceBeyond

func ReplaceBeyond[E any](dest []E, start int, replace ...E) []E

ReplaceBeyond subsitutes replace into dest starting at start. Start can be beyond the current end of dest.

Dest may be modified.

func Splice

func Splice[E any](dest []E, start int, end int, replace ...E) []E

Splice removes replaces dest[start:end] with replace. Replace can be larger or smaller and dest will grow or shrink as needed. Dest will be grown or shrunk as needed.

End must be < len(dest) or else Splice panics.

Dest may be modified.

func SpliceBeyond

func SpliceBeyond[E any](dest []E, start int, end int, replace ...E) []E

SpliceBeyond removes replaces dest[start:end] with replace. Replace can be larger or smaller and dest will grow or shrink as needed. start or end can be beyond the current len or cap of dest and dest will be grown or shrunk as needed.

End must be >= start or else SpliceBeyond panics.

Dest may be modified.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL