-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add intersection,intersectionWith for Data.Map #15
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far, just a couple of minor notes. I think adding these makes sense; intersection
seems a little weird to me in terms of the amount of information it discards, and I don’t think I’ve ever wanted it, but intersectionWith
seems more sensible at least, and also both of these functions already exist in Haskell’s containers
library anyway.
src/Data/Map/Internal.purs
Outdated
-- | Compute the intersection of two maps, preferring values from the first map in the case | ||
-- | of duplicate keys. | ||
intersection :: forall k a b. Ord k => Map k a -> Map k b -> Map k a | ||
intersection = intersectionWith (\a b -> a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit but I think it would be better to use const
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes ofcourse, fixed.
test/Test/Data/Map.purs
Outdated
quickCheck $ \(TestMap m1) (TestMap m2) -> ((m1 :: M.Map SmallKey Int) `M.intersection` m2) == ((m1 `M.intersection` m2) `M.intersection` (m2 :: M.Map SmallKey Int)) | ||
|
||
log "intersectionWith" | ||
for_ [Tuple (+) 0, Tuple (*) 1] $ \(Tuple op ident) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ident
being used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, artifact from unionWith test this is based of. Removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you!
Not sure why these are missing.