package sliceutils
import "git.mstar.dev/mstar/goutils/sliceutils"
Package sliceutils contains various generic functions for applying an operation across an entire slice
Index ¶
- func Compact[T any](a []T, compactor func(acc T, next T) T) T
- func CompareOrdered[T comparable](a, b []T) bool
- func CompareUnordered[T comparable](a, b []T) bool
- func Contains[T comparable](a []T, b T) bool
- func ContainsFunc[T any](a []T, f func(t T) bool) bool
- func Filter[T any](arr []T, filter func(T) bool) []T
- func Map[T any, M any](arr []T, apply func(T) M) []M
- func RemoveDuplicate[T comparable](sliceList []T) []T
- func Reverse[E any](s []E)
Functions ¶
func Compact ¶
func Compact[T any](a []T, compactor func(acc T, next T) T) T
func CompareOrdered ¶
func CompareOrdered[T comparable](a, b []T) bool
CompareOrdered compares two slices for both element equality and element order.
func CompareUnordered ¶
func CompareUnordered[T comparable](a, b []T) bool
CompareUnorderedS compares two slices for element equality. The order of those elements does not matter.
func Contains ¶
func Contains[T comparable](a []T, b T) bool
func ContainsFunc ¶
func Filter ¶
Filter filters a slice using a given function. If the filter function returns true, the element stays, otherwise it gets removed.
func Map ¶
MapS applies a given function to every element of a slice. The return type may be different from the initial type of the slice.
func RemoveDuplicate ¶
func RemoveDuplicate[T comparable](sliceList []T) []T
RemoveDuplicate removes all duplicates inside a slice.
func Reverse ¶
func Reverse[E any](s []E)
Reverse reverses a given slice.
Source Files ¶
sliceUtils.go
- Version
- v1.15.0 (latest)
- Published
- Jun 6, 2025
- Platform
- linux/amd64
- Last checked
- 1 hour ago –
Tools for package owners.