[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36
John Goerzen
jgoerzen at complete.org
Fri Apr 23 14:42:31 UTC 2010
The following commit has been merged in the master branch:
commit df8a1a0563ec0e9d6812e0930642c32662b9aae7
Author: John Goerzen <jgoerzen at complete.org>
Date: Tue Oct 5 21:00:17 2004 +0100
Initial assoc list utilities done
Keywords:
(jgoerzen at complete.org--projects/missingh--head--1.0--patch-13)
diff --git a/MissingH/Listutil.hs b/MissingH/Listutil.hs
index 259e1f8..988e5a4 100644
--- a/MissingH/Listutil.hs
+++ b/MissingH/Listutil.hs
@@ -23,6 +23,12 @@ Written by John Goerzen, jgoerzen\@complete.org
module MissingH.Listutil(-- * Tests
startswith, endswith,
+ -- * Association List Utilities
+ {- | These functions are designed to augment the
+ association list functions in "Data.List" and
+ provide an interface similar to "Data.FiniteMap"
+ for association lists. -}
+ addToAL, delFromAL,
-- * Conversions
split, join, trunc
) where
@@ -97,3 +103,13 @@ trunc maxlen list =
let removecount = (length list) - maxlen in
if (removecount < 1) then list
else reverse $ drop removecount $ reverse list
+
+{- | Adds the specified (key, value) pair to the given list, removing any
+existing pair with the same key already present. -}
+addToAL :: Eq key => [(key, elt)] -> key -> elt -> [(key, elt)]
+addToAL l key value = (key, value) : delFromAL l key
+
+{- | Removes all (key, value) pairs from the given list where the key
+matches the given one. -}
+delFromAL :: Eq key => [(key, a)] -> key -> [(key, a)]
+delFromAL l key = filter (\a -> (fst a) /= key) l
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list