From 878e7471fa09dcc36b478e1ac1fd305d5a90b7bf Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 24 Feb 2014 19:40:14 -0400 Subject: merge from git-annex --- Utility/Env.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Utility/Env.hs') 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 -- cgit v1.2.3