git.iko.soy/distributed-process
on 87bb129 help sign in
21 lines 664 B history raw
1module Control.Distributed.Process.Internal.StrictContainerAccessors
2 ( mapMaybe
3 , mapDefault
4 ) where
6import Prelude hiding (map)
7import Data.Accessor
8import Data.Map (Map)
9import qualified Data.Map as Map (lookup, insert, delete, findWithDefault)
11mapMaybe :: Ord key => key -> Accessor (Map key elem) (Maybe elem)
12mapMaybe key = accessor
13 (Map.lookup key)
14 (\mVal map -> case mVal of
15 Nothing -> Map.delete key map
16 Just val -> val `seq` Map.insert key val map)
18mapDefault :: Ord key => elem -> key -> Accessor (Map key elem) elem
19mapDefault def key = accessor
20 (Map.findWithDefault def key)
21 (\val map -> val `seq` Map.insert key val map)