Documentation
¶
Overview ¶
Package sliceutil provides utility functions for working with slices.
Index ¶
- func Contains(slice []string, item string) bool
- func ContainsAny(s string, substrings ...string) bool
- func ContainsIgnoreCase(s, substr string) bool
- func Deduplicate[T comparable](slice []T) []T
- func Filter[T any](slice []T, predicate func(T) bool) []T
- func FilterMap[T, U any](slice []T, predicate func(T) bool, transform func(T) U) []U
- func FilterMapKeys[K comparable, V any](m map[K]V, predicate func(K, V) bool) []K
- func Map[T, U any](slice []T, transform func(T) U) []U
- func MapToSlice[K comparable, V any](m map[K]V) []K
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsAny ¶
ContainsAny checks if a string contains any of the given substrings.
func ContainsIgnoreCase ¶
ContainsIgnoreCase checks if a string contains a substring, ignoring case.
func Deduplicate ¶ added in v0.39.0
func Deduplicate[T comparable](slice []T) []T
Deduplicate returns a new slice with duplicate elements removed. The order of first occurrence is preserved. This is a pure function that does not modify the input slice.
func Filter ¶ added in v0.39.0
Filter returns a new slice containing only elements that match the predicate. This is a pure function that does not modify the input slice.
func FilterMap ¶ added in v0.39.0
FilterMap filters and transforms elements in a single pass. Only elements where the predicate returns true are transformed and included in the result. This is a pure function that does not modify the input slice.
func FilterMapKeys ¶ added in v0.39.0
func FilterMapKeys[K comparable, V any](m map[K]V, predicate func(K, V) bool) []K
FilterMapKeys returns map keys that match the given predicate. The order of elements is not guaranteed as map iteration order is undefined. This is a pure function that does not modify the input map.
func Map ¶ added in v0.39.0
func Map[T, U any](slice []T, transform func(T) U) []U
Map transforms each element in a slice using the provided function. This is a pure function that does not modify the input slice.
func MapToSlice ¶ added in v0.39.0
func MapToSlice[K comparable, V any](m map[K]V) []K
MapToSlice converts a map's keys to a slice. The order of elements is not guaranteed as map iteration order is undefined. This is a pure function that does not modify the input map.
Types ¶
This section is empty.