Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToMap ¶
func ToMap[T, V any, K comparable](s []T, f func(T) (K, V)) map[K]V
ToMap collects elements of slice to map, both map keys and values are produced by mapping function f.
🚀 EXAMPLE:
type Foo struct {
ID int
Name string
}
mapper := func(f Foo) (int, string) { return f.ID, f.Name }
ToMap([]Foo{}, mapper) ⏩ map[int]string{}
s := []Foo{{1, "one"}, {2, "two"}, {3, "three"}}
ToMap(s, mapper) ⏩ map[int]string{1: "one", 2: "two", 3: "three"}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.