Files
lo/docs/data/core-keyby.md
T
2026-03-02 16:06:51 +01:00

679 B

name, slug, sourceRef, category, subCategory, playUrl, variantHelpers, similarHelpers, position, signatures
name slug sourceRef category subCategory playUrl variantHelpers similarHelpers position signatures
KeyBy keyby slice.go#L374 core slice https://go.dev/play/p/ccUiUL_Lnel
core#slice#keyby
core#slice#keybyerr
core#slice#groupby
core#slice#groupbyerr
core#slice#partitionby
core#map#associate
core#slice#keyify
230
func KeyBy[K comparable, V any](collection []V, iteratee func(item V) K) map[K]V

Transforms a slice to a map using a pivot callback to compute keys.

m := lo.KeyBy(
    []string{"a", "aa", "aaa"},
    func(str string) int {
        return len(str)
    },
)
// map[int]string{1: "a", 2: "aa", 3: "aaa"}