|
|
|
|
|
by metadat
677 days ago
|
|
I want to understand the purpose of maps.All(). In the example: m := map[string]int{"a": 1, "b": 2, "c": 3}
for k, v := range maps.All(m) {
fmt.Printf("%v:%v ", k, v)
}
fmt.Println("")
for k, v := range m {
fmt.Printf("%v:%v ", k, v)
}
These both output the same thing. What's the point of the addition?Slices.All() seems similarly redundant and pointless. Surely I must be misunderstanding something, I hope. |
|
If I create a IterateOver(fn func(func (K, V any) bool)) function, you cannot pass a slice since that doesn’t match fn’s type, but if you wrap it with slices.All it’ll work.