Skip to content

Fix discrepancy between mergeWithKey impl and docs #1025

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

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions containers/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
* `Data.Map.Strict.mergeWithKey` now forces the result of the combining function
to WHNF. (Soumik Sarkar)

* Fix an issue where `Data.Map.mergeWithKey`, `Data.Map.Strict.mergeWithKey`,
`Data.IntMap.mergeWithKey`, `Data.IntMap.Strict.mergeWithKey` could call the
provided `only2` function with empty maps, contrary to documentation.
(Soumik Sarkar)

## Unreleased with `@since` annotation for 0.7.1:

### Additions
Expand Down
2 changes: 2 additions & 0 deletions containers/src/Data/IntMap/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,8 @@ mergeWithKey' bin' f g1 g2 = go
| otherwise = maybe_link k1 (g1 t1) k2 (g2 t2)
merge0 t1 _ Nil = g1 t1

go Nil Nil = Nil

go Nil t2 = g2 t2

maybe_link _ Nil _ t2 = t2
Expand Down
1 change: 1 addition & 0 deletions containers/src/Data/Map/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2782,6 +2782,7 @@ mergeWithKey :: Ord k
-> Map k a -> Map k b -> Map k c
mergeWithKey f g1 g2 = go
where
go Tip Tip = Tip
go Tip t2 = g2 t2
go t1 Tip = g1 t1
go (Bin _ kx x l1 r1) t2 =
Expand Down
1 change: 1 addition & 0 deletions containers/src/Data/Map/Strict/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ mergeWithKey :: Ord k
-> Map k a -> Map k b -> Map k c
mergeWithKey f g1 g2 = go
where
go Tip Tip = Tip
go Tip t2 = g2 t2
go t1 Tip = g1 t1
go (Bin _ kx x l1 r1) t2 =
Expand Down