Add `unionsWith`?
Opened this issue ยท 10 comments
This function doesn't currently exist, but I think it could, and would potentially be useful:
unionsWith :: forall f k v. (Foldable f, Ord k) => (v -> v -> v) -> f (Map k v) -> Map k vIt's probably very simple to define this using what's already exported, but I think it's still useful to have these sorts of things defined for you.
๐
@paf31 just trying to pick up a ticket to get started with contributing, is this being worked on?
I assume this would need the unionsWith function added then exposed and tests?
unionWith is slightly different, it only combines two maps. unionsWith could be used to take the union of an array with any number of maps inside it, for example.
@hdgarrood just got pointed out to me on IRC by garyb as well!! I'll probably get stuck when it comes to testing but I'll crack on :)
For tests, one property to check off the top of my head: the keys of all the maps that were unioned should exist in the resulting map.
Also just to note, we can drop Ord from the signature with the very latest -maps release (it's about 10 minutes old):
unionsWith :: forall f k v. Foldable f => (v -> v -> v) -> f (Map k v) -> Map k v@garyb how would that work??? ๐
With traverse it's fine as we're reconstructing a map in the same way we deconstruct it. But here we're having to combine maps - which means we need to insert the keys in the right place relative to each other.
Uh, yeah, I'm talking nonsense ๐... disregard that.