Open idsulik opened 1 month ago
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
How is Merge different from Copy?
You're right, they're the same, I think we can keep MergeFunc, but replace it with CopyFunc so we can resolve key conflicts
See the discussion for a generic set type: https://github.com/golang/go/discussions/47331 (possibly to be revived soon once iterators land in the next version, as that's what stalled the original discussion)
I also wrote https://pkg.go.dev/github.com/jimmyfrasche/mapset for doing set like things with regular maps
Filter
seems like something for #61898. I don't see why we need a maps-specific filter.
Filter seems like something for https://github.com/golang/go/issues/61898. I don't see why we need a maps-specific filter.
The most important and useful are Diff
and Intersect
.
Filter will be useful for example, if you create map of files using some external package and you need to exclude some files from the map, or you create some items counter map and need to exclude items with less than 10 count
I'm not saying that Filter
is not useful. I'm saying that the Filter2
from #61898 is fine, and we don't also need a separate maps.Filter
.
The most important and useful are Diff and Intersect.
The first thing that I thought when reading the title was how will you compare the values. I think the documentation should mention that only the keys of the maps are used for comparison. IMHO these are not natural operations of maps.
I'm not saying that
Filter
is not useful. I'm saying that theFilter2
from #61898 is fine, and we don't also need a separatemaps.Filter
.
the filter allows you to filter only based on value, this one will also provide you key
I think the documentation should mention that only the keys of the maps are used for comparison
We can add value checking as well, if key is not found or values are diff, then append it to result map
the filter allows you to filter only based on value, this one will also provide you
key
Filter2
filters based on both value and key.
Filter2
filters based on both value and key.
You're right, I missed it. so I think I can implement Diff and Intersect
We can add value checking as well, if key is not found or values are diff
How will you compare the values? Or will you restrict the type constraint of V
to comparable
?
Or will you restrict the type constraint of
V
tocomparable
?
I see only this way for this
I want to propose adding new functions to the maps package:
I'll be happy to contribute a PR with tests if this is a good idea.