Help us shape the future of Go! Take the 2026 Go Developer Survey

sliceutil

package
v0.65.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package sliceutil provides utility functions for working with slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any added in v0.58.0

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

Any returns true if at least one element in the slice satisfies the predicate. Returns false for nil or empty slices. This is a pure function that does not modify the input slice.

func Contains

func Contains(slice []string, item string) bool

Contains checks if a string slice contains a specific string.

func Deduplicate

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

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

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 FilterMapKeys

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

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

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.

Jump to

Keyboard shortcuts

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