Documentation
¶
Overview ¶
Package slices provides generic utility functions for working with slices. These functions are designed to be simple, efficient, and type-safe using Go generics.
Index ¶
- func Contains[T comparable](slice []T, element T) bool
- func ContainsAll[T comparable](slice []T, elements []T) bool
- func ContainsAny[T comparable](slice []T, elements []T) bool
- func Copy[T any](slice []T) []T
- func Filter[T any](slice []T, predicate func(T) bool) []T
- func First[T any](slice []T) (T, bool)
- func IndexOf[T comparable](slice []T, element T) int
- func Last[T any](slice []T) (T, bool)
- func Map[T any, R any](slice []T, transform func(T) R) []R
- func Unique[T comparable](slice []T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](slice []T, element T) bool
Contains returns true if the slice contains the given element. Uses comparable constraint for type-safe equality comparison.
func ContainsAll ¶
func ContainsAll[T comparable](slice []T, elements []T) bool
ContainsAll returns true if the slice contains all of the given elements.
func ContainsAny ¶
func ContainsAny[T comparable](slice []T, elements []T) bool
ContainsAny returns true if the slice contains any of the given elements.
func First ¶
First returns the first element of the slice and true, or zero value and false if empty.
func IndexOf ¶
func IndexOf[T comparable](slice []T, element T) int
IndexOf returns the index of the first occurrence of element in the slice, or -1 if the element is not found.
func Unique ¶
func Unique[T comparable](slice []T) []T
Unique returns a new slice with duplicate elements removed. Preserves the order of first occurrence.
Types ¶
This section is empty.