Files
lo/docs/data/core-groupbymap.md
T
Nathan Baulch e7386d9246 lint: fix inconsistent callback function parameter names (#730)
* Fix linting

* Use is.ElementsMatch

This will ignore the ordering of the final intersection. Especially
important when checking old versions of go that do not guarantee an order
when iterating through maps.

* lint: fix inconsistent callback function parameter names

* lint: rename "iteratee" to "transform" for *Map helpers

* lint: rename "project" parameters to "transform"

* lint: rename "cb" parameters to "callback"

* lint: rename "iteratee" to "callback" for ForEach helpers

---------

Co-authored-by: Franky W. <frankywahl@users.noreply.github.com>
Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
2025-11-06 18:05:11 +01:00

718 B

name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory playUrl variantHelpers similarHelpers position signatures
GroupByMap groupbymap slice.go#L194 core slice https://go.dev/play/p/iMeruQ3_W80
core#slice#groupbymap
core#slice#groupby
core#slice#partitionby
core#slice#keyby
core#map#associate
parallel#slice#groupby
130
func GroupByMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K][]V

Groups items by a key computed from each element and maps each element to a value.

groups := lo.GroupByMap(
    []int{0, 1, 2, 3, 4, 5},
    func(i int) (int, int) {
        return i % 3, i * 2
    },
)
// map[int][]int{0:{0,6}, 1:{2,8}, 2:{4,10}}