Back to Lo

It Keyby

docs/data/it-keyby.md

1.53.0255 B
Original Source

Transforms a sequence into a map using a transform function to generate keys.

go
result := it.KeyBy(it.Range(1, 5), func(item int) string {
    return fmt.Sprintf("key-%d", item)
})
// map[string]int{"key-1": 1, "key-2": 2, "key-3": 3, "key-4": 4}