Created
February 16, 2020 10:21
-
-
Save YoEight/52bf7648ed9088158584d599ee1aa59a to your computer and use it in GitHub Desktop.
How delete for Map should be.
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
import Data.Map (Map) | |
import Data.Map as Map | |
-------------------------------------------------------------------------------- | |
-- | I'm bad at naming thing however, we are going to use that datastructure | |
-- so we could lookup and delete in one single pass. | |
data Blob a b = Blob a b | |
-------------------------------------------------------------------------------- | |
instance Functor (Blob a) where | |
fmap f (Blob a b) = Blob a (f b) | |
-------------------------------------------------------------------------------- | |
deleteMap :: k -> Map k v -> (Maybe v, Map k v) | |
deleteMap key ms = | |
let Blob result newMs = | |
Map.alterF go key ms in | |
(result, newMs) | |
where | |
go Nothing = Blob Nothing Nothing | |
go (Just e) = Blob (Just e) Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment