Skip to main content Link Search Menu Expand Document (external link)

ToMap

func ToMap[T any, K comparable](input *Channel[T], getKey func(T) K, opts ...options.ToMapOption) <-chan map[K]T

ToMap puts all values coming from the input channel in a map, using the getKey parameter to calculate the key.

The resulting map is sent to the returned channel when all input values have been processed, or the pipeline is canceled.

Example

output := ToMap(input, func(value string) string { return strings.Split(value, "_")[0] })

result = {A:A_0, B:B_1, C:C_2}