Documentation
¶
Overview ¶
Package slices provides generic slice operations such as unique, filter, chunk, and flatten.
Index ¶
- func AppendBounded[T any](s []T, v T, limit int) []T
- func ChunkSlice[T any](slice []T, chunkSize int) [][]T
- func ConcatKeepLast[T any](chunks [][]T, limit int) []T
- func ContainsInSlice[T comparable](slice []T, value T) bool
- func ExcludeFromSlice[T comparable](slice, excludeValues []T) []T
- func KeepLast[T any](s []T, limit int) []T
- func MapSlice[T, U any](src []T, converter func(T) U) []U
- func UniqueComparable[T comparable](slice []T) []T
- func UniqueSlice[T fmt.Stringer](slice []T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendBounded ¶
AppendBounded appends v while capping at limit elements, shifting out the oldest when full. If limit <= 0, s is unchanged.
func ChunkSlice ¶
ChunkSlice splits a slice into chunks of the specified size. The last chunk may be smaller than chunkSize if the slice length is not divisible by chunkSize.
func ConcatKeepLast ¶
ConcatKeepLast flattens chunks, then KeepLast(flat, limit).
func ContainsInSlice ¶
func ContainsInSlice[T comparable](slice []T, value T) bool
ContainsInSlice checks if value exists in slice. Returns true if found, false otherwise.
func ExcludeFromSlice ¶
func ExcludeFromSlice[T comparable](slice, excludeValues []T) []T
ExcludeFromSlice returns a new slice with all values from excludeValues removed from slice not optimized for performance
func KeepLast ¶
KeepLast returns a new slice with the last up to limit elements, or nil if limit <= 0.
func MapSlice ¶
func MapSlice[T, U any](src []T, converter func(T) U) []U
MapSlice applies a converter function to each element of src and returns a new slice. The result slice has the same length as src.
func UniqueComparable ¶
func UniqueComparable[T comparable](slice []T) []T
UniqueComparable returns a new slice containing only unique elements from the input. Uniqueness is determined by ==. Order is preserved (first occurrence kept).
func UniqueSlice ¶
UniqueSlice returns a new slice containing only unique elements from the input. Uniqueness is determined by the String() method of each element. The order of elements is preserved (first occurrence is kept).
Types ¶
This section is empty.