diff options
author | Joey Hess <joey@kitenet.net> | 2014-02-24 19:40:14 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-02-24 19:40:14 -0400 |
commit | 878e7471fa09dcc36b478e1ac1fd305d5a90b7bf (patch) | |
tree | d552b8faa43078e3dfe1f8b10063ec566eced4e2 /Utility/Env.hs | |
parent | d80c547a7d1261f158148ca85e627cc2ecb005f2 (diff) | |
download | git-repair-878e7471fa09dcc36b478e1ac1fd305d5a90b7bf.tar.gz |
merge from git-annex
Diffstat (limited to 'Utility/Env.hs')
-rw-r--r-- | Utility/Env.hs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Utility/Env.hs b/Utility/Env.hs index cb73873..90ed58f 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 |