immutableslice

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append[S ~[]E, E any](s S, e ...E) S

Append will create a new slice with the elements of s followed by the elements of e. This is a shorthand for a call to Concat(s, e) that allows passing the elements to append as variadic arguments.

func Compact

func Compact[S ~[]E, E comparable](s S) S

Compact is an immutable variant of the standard libraries slices.Compact function. It will replace consecutive runs of equal elements with the first instance.

func CompactFunc

func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S

CompactFunc is an immutable variant of the standard libraries slices.CompactFunc function. It will replace consecutive runs of elements for which the eq function returns true with with the first instance.

func Concat

func Concat[S ~[]E, E any](slices ...S) S

Concat is an immutable variant of the stdlibs slices.Concat function. It will create a new slice (with a newly allocated backing array) that stores all elements of the specified slices in the order that they were specified.

func Delete

func Delete[S ~[]E, E any](s S, i, j int) S

Delete is an immutable variant of the standard libraries slices.Delete function. It will delete all elements at indexes from i up to but excluding j from the slice. The underlying slice and its backing array will not be modified in any way. When this function returns a non-nil value, the returned slice will be backed by a fresh array and so modifications to the output will not affect the input slice. Note that this will not copy the slice elements so care must still be taken to ensure no modifications to those elements if that is the desired constraint.

func DeleteFunc

func DeleteFunc[S ~[]E, E any](s S, del func(E) bool) S

DeleteFunc is an immutable variant of the standard libraries slices.DeleteFunc function. This function will return a new slice with all elements of s for which the del function returns false. The underlying slice and its backing array will not be modified.

func Insert

func Insert[S ~[]E, E any](s S, i int, v ...E) S

Insert is an immutable variant of the standard libraries slices.Insert function. It will insert the elements of v at index i in the slice s. The original slices will not be modified in any way.

func Prepend

func Prepend[S ~[]E, E any](s S, e ...E) S

Prepend will create a new slice with the elements of e followed by the elements of s. This is a shorthand for a call to Concat(e, s) that allows passing the elements to prepend as variadic arguments.

func Replace

func Replace[S ~[]E, E any](s S, i, j int, v ...E) S

Replace is an immutable variant of the standard libraries slices.Replace function. It will replace the elements represented by s[i:j] with the elements of v.

func Reverse

func Reverse[S ~[]E, E any](s S) S

Reverse is an immutable variant of the standard libraries slices.Reverse function. It will create a new slice with a fresh backing array and populate it with elements from s in reverse order.

func Sort

func Sort[S ~[]E, E cmp.Ordered](s S) S

Sort is an immutable variant of the standard libraries slices.Sort function. It is a small wrapper which will clone the slice and then sort it to ensure that the original is not modified.

func SortFunc

func SortFunc[S ~[]E, E any](s S, cmp func(a, b E) int) S

SortFunc is an immutable variant of the standard libraries slices.SortFunc function. It is a small wrapper which will clone the slice and then sort it to ensure that the original is not modified.

func SortStableFunc

func SortStableFunc[S ~[]E, E any](s S, cmp func(a, b E) int) S

SortStableFunc is an immutable variant of the standard libraries slices.SortStableFunc function. It is a small wrapper which will clone the slice and then sort it to ensure that the original is not modified.

Types

This section is empty.

Jump to

Keyboard shortcuts

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