sliceutil

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MPL-2.0 Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sliceutil contains helpers related to slices, usually ones that are generic-related, and are broadly useful, but which the Go core team, in its infinite wisdom, has decided are too much power for the unwashed mashes, and therefore omitted from the utilities in `slices`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstNonEmpty

func FirstNonEmpty[T any](inputs ...[]T) []T

FirstNonEmpty returns the first non-empty slice from the input, or nil if all input slices are empty.

func GroupBy

func GroupBy[T any, U comparable](collection []T, keyFunc func(T) U) map[U][]T

GroupBy returns an object composed of keys generated from the results of running each element of collection through keyFunc.

func KeyBy

func KeyBy[T any, K comparable, V any](collection []T, tupleFunc func(item T) (K, V)) map[K]V

KeyBy converts a slice into a map using the key/value tuples returned by tupleFunc. If any two pairs would have the same key, the last one wins. Go maps are unordered and the order of the new map isn't guaranteed to the same as the original slice.

func Map

func Map[T any, R any](collection []T, mapFunc func(T) R) []R

Map manipulates a slice and transforms it to a slice of another type.

func MapError

func MapError[T any, R any](collection []T, mapFunc func(T) (R, error)) ([]R, error)

MapError manipulates a slice and transforms it to a slice of another type, returning the first error that occurred invoking the map function, if there was one.

func Uniq

func Uniq[T comparable](collection []T) []T

Uniq returns a duplicate-free version of an array, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array.

Types

This section is empty.

Jump to

Keyboard shortcuts

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