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

Strict.mapMaybe[WithKey] too lazy in collision contents #381

Closed
sjakobi opened this issue Mar 19, 2022 · 0 comments · Fixed by #385
Closed

Strict.mapMaybe[WithKey] too lazy in collision contents #381

sjakobi opened this issue Mar 19, 2022 · 0 comments · Fixed by #385
Assignees
Labels

Comments

@sjakobi
Copy link
Member

sjakobi commented Mar 19, 2022

-- | /O(n)/ Transform this map by applying a function to every value
-- and retaining only some of them.
mapMaybeWithKey :: (k -> v1 -> Maybe v2) -> HashMap k v1 -> HashMap k v2
mapMaybeWithKey f = filterMapAux onLeaf onColl
where onLeaf (Leaf h (L k v)) | Just v' <- f k v = Just (leaf h k v')
onLeaf _ = Nothing
onColl (L k v) | Just v' <- f k v = Just (L k v')
| otherwise = Nothing
{-# INLINE mapMaybeWithKey #-}
-- | /O(n)/ Transform this map by applying a function to every value
-- and retaining only some of them.
mapMaybe :: (v1 -> Maybe v2) -> HashMap k v1 -> HashMap k v2
mapMaybe f = mapMaybeWithKey (const f)
{-# INLINE mapMaybe #-}

I think there's a problem in line 551: v' isn't forced.

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