sliceutil

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone[T any](in []T) []T

Clone returns a shallow copy of a slice while preserving nil input as nil.

func Contains

func Contains[T comparable](values []T, want T) bool

Contains reports whether values includes want.

func ContainsFunc

func ContainsFunc[T any](values []T, match func(T) bool) bool

ContainsFunc reports whether any value satisfies match.

func FilterMap

func FilterMap[T any, U any](values []T, fn func(T) (U, bool)) []U

FilterMap returns mapped values for inputs accepted by fn while preserving nil input as nil. A nil fn rejects every value.

func First

func First[T any](values []T) T

First returns the first value from values, or the zero value when values is empty.

func IndexBy

func IndexBy[T any, K comparable](values []T, key func(T) (K, bool)) map[K]int

IndexBy builds an index of the first position for each accepted key in values.

func Limit

func Limit[T any](values []T, limit int) []T

Limit returns values truncated to at most limit items. A non-positive limit means no truncation, matching call sites where zero is an unset limit.

func LimitClone

func LimitClone[T any](values []T, limit int) []T

LimitClone returns a shallow copy truncated to at most limit items. A non-positive limit means no truncation.

func Map

func Map[T any, U any](values []T, fn func(T) U) []U

Map returns a slice containing fn applied to each value while preserving nil input as nil. A nil fn returns the zero value for each input element.

func ReverseClone

func ReverseClone[T any](in []T) []T

ReverseClone returns a new slice with values from in in reverse order.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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