Documentation ¶
Overview ¶
Package slicehelper contains slice-related helpers.
Index ¶
- func Map[S ~[]Es, R ~[]Er, Es, Er any](s S, m func(Es) Er) R
- func RemoveInPlace[S ~[]E, E any](s S, idx int) (S, error)
- func ReverseNew[S ~[]E, E any](s S) S
- func SortDesc[S ~[]E, E cmp.Ordered](x S)
- func Split(len, n int) ([]int, error)
- func Trim[S ~[]E, E any](s S, f func(E) bool) S
- func TrimEnd[S ~[]E, E any](s S, f func(E) bool) S
- func TrimStart[S ~[]E, E any](s S, f func(E) bool) S
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Map ¶ added in v0.5.0
func Map[S ~[]Es, R ~[]Er, Es, Er any](s S, m func(Es) Er) R
Map projects the elements of 's' into a new slice.
func RemoveInPlace ¶
RemoveInPlace removes in place from 's' the element at the specified index.
func ReverseNew ¶
func ReverseNew[S ~[]E, E any](s S) S
ReverseNew returns new slice containing the reversed elements of 's'. The initial slice remains unchanged. If 's' is nil, nil is returned.
func SortDesc ¶ added in v0.2.0
SortDesc is like slices.Sort but sorts a slice in descending order.
func Split ¶
Split splits a sequence of ints [0..'len'-1] (indexes of a slice with length 'len') into 'n' as equal as possible integer parts. 'len' and 'n' must be greater than 1. 'len' must not be less than 'n'. The result contains start indexes of the parts and 'len', so each consecutive pair of the result's elements may be used as 'low' and 'high' indices for subslicing (see TestSplit for example). Function is intended for splitting a slice for (parallel) processing of the parts.
func Trim ¶ added in v0.4.0
Trim removes all leading and trailing elements from 's' that satisfy 'f'. If 's' is nil or empty or 'f' is nil, 's' is returned.
Types ¶
This section is empty.