slices

package
v0.5.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 1 Imported by: 0

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

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 Copy

func Copy[T any](slice []T) []T

Copy returns a shallow copy of the slice.

func Filter

func Filter[T any](slice []T, predicate func(T) bool) []T

Filter returns a new slice containing only elements that satisfy the predicate.

func First

func First[T any](slice []T) (T, bool)

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 Last

func Last[T any](slice []T) (T, bool)

Last returns the last element of the slice and true, or zero value and false if empty.

func Map

func Map[T any, R any](slice []T, transform func(T) R) []R

Map transforms each element in the slice using the given function.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL