Skip to content
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

Map and IntMap updateLookupWithKey have different behaviors #1089

Open
meooow25 opened this issue Jan 10, 2025 · 0 comments
Open

Map and IntMap updateLookupWithKey have different behaviors #1089

meooow25 opened this issue Jan 10, 2025 · 0 comments

Comments

@meooow25
Copy link
Contributor

Data.Map.updateLookupWithKey and Data.IntMap.updateLookupWithKey have different behaviors on replacement.

-- | \(O(\log n)\). Lookup and update. See also 'updateWithKey'.
-- The function returns changed value, if it is updated.
-- Returns the original key value if the map entry is deleted.

-- | \(O(\min(n,W))\). Lookup and update.
-- The function returns original value, if it is updated.
-- This is different behavior than 'Data.Map.updateLookupWithKey'.
-- Returns the original key value if the map entry is deleted.

This really bothers me, but I don't think we should change one of them to be like the other because it could introduce a subtle bug for existing users.

Hackage Search (https://hackage-search.serokell.io/?q=updateLookupWithKey) indicates that most users are using it as updateLookupWithKey (\_ _ -> Nothing), which means they want to delete an entry and get the deleted value. This suggests that it would be useful have a function for that purpose.
But even if we add that, we can't get rid of updateLookupWithKey because there is a lot of code out there using the function. The two implementations have been around since the very beginning (bbbba97).

Maybe we just have to live with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant