They’re useful because they let you pass a slice or map to something built to handle the new func(func (…) bool) style iterators.
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.
Re:Go 1.23 Released
by ianlancetaylor on Tuesday August 13, 2024 @06:08PM
(#41240349)
You can use it with other functions that use iterators. For example, here is code that makes a copy of a map keeping only the even keys.
maps.Collect(xiter.Filter2(func(k, v int) bool { return k%2 == 0 }, maps.All(m)))
In the example:
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.