collection

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk[T any](in []T, n int) [][]T

Chunk splits the slice into chunks of size n. Returns empty when n<=0.

func Filter

func Filter[T any](in []T, pred func(T) bool) []T

Filter filters slice elements by predicate.

func GroupBy

func GroupBy[T any, K comparable](in []T, key func(T) K) map[K][]T

GroupBy groups slice elements by key.

func Invert

func Invert[K comparable, V comparable](m map[K]V) map[V]K

Invert reverses map[K]V to map[V]K; later entries overwrite earlier ones on conflicts.

func Keys

func Keys[M ~map[K]V, K comparable, V any](m M) []K

Keys returns all keys of the map (unordered).

func Map

func Map[A any, B any](in []A, f func(A) B) []B

Map maps slice elements to another type.

func Merge

func Merge[K comparable, V any](dst, src map[K]V) map[K]V

Merge merges src into dst and returns dst (in-place modification).

func Unique

func Unique[T comparable](in []T) []T

Unique returns a de-duplicated slice preserving the first occurrence order.

func Values

func Values[M ~map[K]V, K comparable, V any](m M) []V

Values returns all values of the map.

Types

type Set

type Set[T comparable] map[T]struct{}

func NewSet

func NewSet[T comparable](vals ...T) Set[T]

func (Set[T]) Add

func (s Set[T]) Add(v T)

func (Set[T]) Del

func (s Set[T]) Del(v T)

func (Set[T]) Diff

func (s Set[T]) Diff(t Set[T]) Set[T]

func (Set[T]) Has

func (s Set[T]) Has(v T) bool

func (Set[T]) Intersect

func (s Set[T]) Intersect(t Set[T]) Set[T]

func (Set[T]) Len

func (s Set[T]) Len() int

func (Set[T]) ToSlice

func (s Set[T]) ToSlice() []T

func (Set[T]) Union

func (s Set[T]) Union(t Set[T]) Set[T]

Jump to

Keyboard shortcuts

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