sliceutil

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 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 added in v0.39.0

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 added in v0.39.0

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 added in v0.39.0

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 added in v0.39.0

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 added in v0.39.0

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 added in v0.39.0

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