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

sliceutil

package
v0.43.12 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 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 Contains

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

Contains checks if a string slice contains a specific string.

func ContainsAny

func ContainsAny(s string, substrings ...string) bool

ContainsAny checks if a string contains any of the given substrings.

func ContainsIgnoreCase

func ContainsIgnoreCase(s, substr string) bool

ContainsIgnoreCase checks if a string contains a substring, ignoring case.

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 FilterMap

func FilterMap[T, U any](slice []T, predicate func(T) bool, transform func(T) U) []U

FilterMap filters and transforms elements in a single pass. Only elements where the predicate returns true are transformed and included in the result. 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