batch

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 1 Imported by: 0

README

Batch

This package provides helpers for safe, predictable batch operations on maps and slices.

naming convention

  • Get...: read a value from an existing map by key.
  • Transform...: apply a value transformation while preserving collection shape.
  • Index...: build a map from a slice using a key selector.
  • Group...: build a map of slices from a slice using a key selector.
  • ...By...: indicates the function uses a key selector.
  • ...To...: indicates the function both uses a key selector and transforms the values.

E.g.

  • IndexBy...: build map[K]V from []V using a key selector.
  • IndexTo...: build map[K]O from []I with both key selection and value transformation.
  • GroupBy...: build map[K][]V from []V by key.
  • GroupTo...: build map[K][]O from []I by key with value projection.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMapSlice

func GetMapSlice[K comparable, V any](itemsMap map[K][]V, key K) ([]V, error)

func GetMapValue

func GetMapValue[K comparable, V any](itemMap map[K]V, key K) (item V, err error)

func GroupBy

func GroupBy[I, K comparable](items []I, keyFn func(item *I) K) (map[K][]I, error)

func GroupTo

func GroupTo[I, K comparable, O any](items []I, keyFn func(item *I) K, parseFn func(item *I) O) (map[K][]O, error)

func IndexBy

func IndexBy[I, K comparable](items []I, keyFn func(item *I) K) (map[K]I, error)

func IndexTo

func IndexTo[I, K comparable, O any](items []I, keyFn func(item *I) K, parseFn func(item *I) O) (map[K]O, error)

func TransformMapSlices

func TransformMapSlices[K comparable, V, O any](itemsMap map[K][]V, parseFn func([]V) []O) map[K][]O

func TransformMapValues

func TransformMapValues[K comparable, V, O any](itemsMap map[K]V, parseFn func(V) O) map[K]O

func TransformSlice

func TransformSlice[I, O any](items []I, parseFn func(item I) O) []O

func Unique added in v1.1.0

func Unique[K comparable](items []K) []K

Types

This section is empty.

Jump to

Keyboard shortcuts

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