Documentation
¶
Index ¶
- func Chunk[T any](in []T, n int) [][]T
- func Filter[T any](in []T, pred func(T) bool) []T
- func GroupBy[T any, K comparable](in []T, key func(T) K) map[K][]T
- func Invert[K comparable, V comparable](m map[K]V) map[V]K
- func Keys[M ~map[K]V, K comparable, V any](m M) []K
- func Map[A any, B any](in []A, f func(A) B) []B
- func Merge[K comparable, V any](dst, src map[K]V) map[K]V
- func Unique[T comparable](in []T) []T
- func Values[M ~map[K]V, K comparable, V any](m M) []V
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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]
Click to show internal directories.
Click to hide internal directories.