summaryrefslogtreecommitdiff
path: root/Utility/Env.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-01-14 16:42:10 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-01-14 16:42:10 -0400
commit619e567cc8b59b549f70c95357455ac95fec942d (patch)
tree3f17722168b5bc9844b2c86dde80dab854ded548 /Utility/Env.hs
parentb52ce804b084b9c182756bb6df944f0604b26f5b (diff)
avoid needing a build-dep on hxt for Data.AssocList
Diffstat (limited to 'Utility/Env.hs')
-rw-r--r--Utility/Env.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/Utility/Env.hs b/Utility/Env.hs
index cb738732f..90ed58f6b 100644
--- a/Utility/Env.hs
+++ b/Utility/Env.hs
@@ -61,3 +61,21 @@ unsetEnv var = do
#else
unsetEnv _ = return False
#endif
+
+{- Adds the environment variable to the input environment. If already
+ - present in the list, removes the old value.
+ -
+ - This does not really belong here, but Data.AssocList is for some reason
+ - buried inside hxt.
+ -}
+addEntry :: Eq k => k -> v -> [(k, v)] -> [(k, v)]
+addEntry k v l = ( (k,v) : ) $! delEntry k l
+
+addEntries :: Eq k => [(k, v)] -> [(k, v)] -> [(k, v)]
+addEntries = foldr (.) id . map (uncurry addEntry) . reverse
+
+delEntry :: Eq k => k -> [(k, v)] -> [(k, v)]
+delEntry _ [] = []
+delEntry k (x@(k1,_) : rest)
+ | k == k1 = rest
+ | otherwise = ( x : ) $! delEntry k rest