-
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dfbd7e2
Add intersection,intersectionWith
karshan bec0126
Merge branch 'master' of https://github.com/purescript/purescript-ord…
karshan b8af9ab
Make intersectionWith test more precise
karshan c350f8d
Remove unused value in intersectionWith test
karshan ca68958
Data.Map.intersection: Use const
karshan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,23 @@ mapTests = do | |
Just v -> Just v == v2 | ||
Nothing -> not (in1 || in2) | ||
|
||
log "Lookup from intersection" | ||
quickCheck $ \(TestMap m1) (TestMap m2) k -> | ||
M.lookup (smallKey k) (M.intersection (m1 :: M.Map SmallKey Int) (m2 :: M.Map SmallKey Int)) == (case M.lookup k m2 of | ||
Nothing -> Nothing | ||
Just v -> M.lookup k m1) <?> ("m1: " <> show m1 <> ", m2: " <> show m2 <> ", k: " <> show k <> ", v1: " <> show (M.lookup k m1) <> ", v2: " <> show (M.lookup k m2) <> ", intersection: " <> show (M.intersection m1 m2)) | ||
|
||
log "Intersection is idempotent" | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, artifact from unionWith test this is based of. Removed. |
||
quickCheck $ \(TestMap m1) (TestMap m2) k -> | ||
let u = M.intersectionWith op m1 m2 :: M.Map SmallKey Int | ||
in case M.lookup k u of | ||
Nothing -> not (M.member k m1 && M.member k m2) | ||
Just v -> Just v == (op <$> M.lookup k m1 <*> M.lookup k m2) | ||
|
||
log "difference" | ||
quickCheck $ \(TestMap m1) (TestMap m2) -> | ||
let d = M.difference (m1 :: M.Map SmallKey Int) (m2 :: M.Map SmallKey String) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.