summaryrefslogtreecommitdiff
path: root/compiler/GHC/Unit/Module
diff options
context:
space:
mode:
authorM Farkas-Dyck <strake888@proton.me>2022-09-29 01:03:13 -0800
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-10-19 10:46:29 -0400
commit83638dce4e20097b9b7073534e488a92dce6e88f (patch)
treee18b4b2484354c8875914a4b35a37d0377258eb4 /compiler/GHC/Unit/Module
parentf7b7a3122185222d5059e37315991afcf319e43c (diff)
downloadhaskell-83638dce4e20097b9b7073534e488a92dce6e88f.tar.gz
Scrub various partiality involving lists (again).
Lets us avoid some use of `head` and `tail`, and some panics.
Diffstat (limited to 'compiler/GHC/Unit/Module')
-rw-r--r--compiler/GHC/Unit/Module/Env.hs6
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/GHC/Unit/Module/Env.hs b/compiler/GHC/Unit/Module/Env.hs
index 0c0559e206..aec4add585 100644
--- a/compiler/GHC/Unit/Module/Env.hs
+++ b/compiler/GHC/Unit/Module/Env.hs
@@ -9,7 +9,7 @@ module GHC.Unit.Module.Env
, partitionModuleEnv
, moduleEnvKeys, moduleEnvElts, moduleEnvToList
, unitModuleEnv, isEmptyModuleEnv
- , extendModuleEnvWith, filterModuleEnv
+ , extendModuleEnvWith, filterModuleEnv, mapMaybeModuleEnv
-- * ModuleName mappings
, ModuleNameEnv, DModuleNameEnv
@@ -94,6 +94,10 @@ filterModuleEnv :: (Module -> a -> Bool) -> ModuleEnv a -> ModuleEnv a
filterModuleEnv f (ModuleEnv e) =
ModuleEnv (Map.filterWithKey (f . unNDModule) e)
+mapMaybeModuleEnv :: (Module -> a -> Maybe b) -> ModuleEnv a -> ModuleEnv b
+mapMaybeModuleEnv f (ModuleEnv e) =
+ ModuleEnv (Map.mapMaybeWithKey (f . unNDModule) e)
+
elemModuleEnv :: Module -> ModuleEnv a -> Bool
elemModuleEnv m (ModuleEnv e) = Map.member (NDModule m) e