Back to Lo

Core Groupbymap

docs/data/core-groupbymap.md

1.53.0258 B
Original Source

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

go
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}}