Documentation
¶
Overview ¶
Package slicesx provides slice utilities that compliment Go standard slices package.
Index ¶
- func Fanout[S ~[]E, E any](seq S, fn func(int, E))
- func FanoutErr[S ~[]E, E any](seq S, fn func(int, E) error) error
- func Filter[S ~[]E, E any](s S, fn func(E) bool) S
- func FilterMap[S ~[]In, In any, Out any](s S, fn func(In) (Out, bool)) []Out
- func Flatten[E any](s [][]E) []E
- func For[S ~[]E, E any](seq S, fn func(int, E))
- func ForErr[S ~[]E, E any](seq S, fn func(int, E) error) error
- func Generate[E any](n int, fn func(int) E) []E
- func Map[S ~[]E, E any, Out any](s S, fn func(E) Out) []Out
- func MapErr[S ~[]E, E any, Out any](s S, fn func(E) (Out, error)) (out []Out, err error)
- func MapIndex[S ~[]E, E any, Out any](s S, fn func(int, E) Out) []Out
- func MapIndexSafe[S ~[]E, E any, Out any](s S, fn func(int, E) Out) (_ []Out, err error)
- func MapSafe[S ~[]E, E any, Out any](s S, fn func(E) Out) (_ []Out, err error)
- func Normalize[S ~[]E, E comparable](s S) S
- func ParaMap[S ~[]E, E any, Out any](s S, fn func(E) Out) []Out
- func ParaMapErr[S ~[]E, E any, Out any](s S, fn func(E) (Out, error)) (out []Out, err error)
- func PopBack[S ~[]E, E any](s *S) E
- func PopBackSafe[S ~[]E, E any](s *S) (e E, ok bool)
- func PopFront[S ~[]E, E any](s *S) E
- func PopFrontSafe[S ~[]E, E any](s *S) (e E, ok bool)
- func Repeat[E any](n int, v E) []E
- func Take[S ~[]E, E any](s *S, index int) E
- func TakeAllFunc[S ~[]E, E any](s *S, fn func(E) bool) (S, bool)
- func TakeFunc[S ~[]E, E any](s *S, fn func(E) bool) (E, bool)
- func TakeRange[S ~[]E, E any](s *S, start, end int) S
- func TakeRangeSafe[S ~[]E, E any](s *S, start, end int) (S, bool)
- func TakeSafe[S ~[]E, E any](s *S, index int) (E, bool)
- func ToMap[S ~[]E, E any, K comparable](s S, keyFor func(int, E) K) map[K]E
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fanout ¶
Fanout across all elements of a slice in parallel. The function receives the index and element.
func MapErr ¶
MapErr transforms a slice by applying a fallible function to each element and returning the result.
If the function returns an error the map operation completes, returning an aggregated error for each failed transform. The output list will be short by the number of failures. Length of the output is not guaranteed to match that of the input.
func MapIndexSafe ¶
MapIndexSafe is like MapIndex but recovers from panics and returns an error instead.
func Normalize ¶
func Normalize[S ~[]E, E comparable](s S) S
Normalize de-duplicates a slices of comparable elements. Doesn't rely on sorting.
func ParaMap ¶
ParaMap transforms a slice by applying a function to each element and returning the result. Transforms are executed concurrently.
func ParaMapErr ¶
ParaMapErr is MapErr, but all instances of fn run concurrently.
func PopBackSafe ¶
PopBackSafe returns the last element from the slice, or false.
func PopFront ¶
func PopFront[S ~[]E, E any](s *S) E
PopFront returns the first element from the slice.
func PopFrontSafe ¶
PopFrontSafe returns the first element from the slice, or false.
func TakeAllFunc ¶
TakeAllFunc selects all items for which [fn] returns true and removes them from the slice.
func TakeRange ¶
TakeRange selects all items between [start] and [end] and removes them from the slice. Does not bounds check.
func TakeRangeSafe ¶
TakeRangeSafe selects all items between [start] and [end] and removes them from the slice. Checks the bounds.
func ToMap ¶
func ToMap[S ~[]E, E any, K comparable](s S, keyFor func(int, E) K) map[K]E
ToMap converts a slice to a map, using [keyFor] to extract the key from each element.
Types ¶
This section is empty.