[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:30 UTC 2010
The following commit has been merged in the master branch:
commit cd4a880053a94598812fd0e51fec626e310999e0
Author: John Goerzen <jgoerzen at complete.org>
Date: Tue Oct 5 20:49:44 2004 +0100
Finished with Strutil
Keywords:
(jgoerzen at complete.org--projects/missingh--head--1.0--patch-12)
diff --git a/MissingH/Listutil.hs b/MissingH/Listutil.hs
index 03f29fc..259e1f8 100644
--- a/MissingH/Listutil.hs
+++ b/MissingH/Listutil.hs
@@ -24,12 +24,12 @@ Written by John Goerzen, jgoerzen\@complete.org
module MissingH.Listutil(-- * Tests
startswith, endswith,
-- * Conversions
- split, join
+ split, join, trunc
) where
-import Data.List(intersperse)
+import Data.List(intersperse, concat, isPrefixOf, isSuffixOf)
{- | Returns true if the given list starts with the specified elements;
-false otherwise.
+false otherwise. (This is an alias for "Data.List.isPrefixOf".)
Example:
@@ -38,14 +38,10 @@ Example:
-}
startswith :: Eq a => [a] -> [a] -> Bool
-startswith [] _ = True
-startswith _ [] = False
-startswith (x:xs) (l:ls) =
- if (x == l) then startswith xs ls
- else False
+startswith = isPrefixOf
{- | Returns true if the given list ends with the specified elements;
-false otherwise.
+false otherwise. (This is an alias for "Data.List.isSuffixOf".)
Example:
@@ -53,7 +49,7 @@ Example:
-}
endswith :: Eq a => [a] -> [a] -> Bool
-endswith x l = startswith (reverse x) (reverse l)
+endswith = isSuffixOf
{- | Given a delimiter and a list (or string), split into components.
@@ -84,5 +80,20 @@ Example:
> join "|" ["foo", "bar", "baz"] -> "foo|bar|baz"
-}
-join :: a -> [a] -> a
-join delim l = foldl (++) [] (intersperse delim l)
+join :: [a] -> [[a]] -> [a]
+join delim l = concat (intersperse delim l)
+
+{- | Given a length and a list, remove any elements at the end of the list
+that make it longer than the length. If the list is shorter than the
+length, do nothing.
+
+Example:
+
+> trunc 2 "Hello" -> "He"
+-}
+
+trunc :: Int -> [a] -> [a]
+trunc maxlen list =
+ let removecount = (length list) - maxlen in
+ if (removecount < 1) then list
+ else reverse $ drop removecount $ reverse list
diff --git a/MissingH/Strutil.hs b/MissingH/Strutil.hs
index ae8cebd..e05aef1 100644
--- a/MissingH/Strutil.hs
+++ b/MissingH/Strutil.hs
@@ -28,9 +28,11 @@ module MissingH.Strutil(-- * Whitespace Removal
-- in "MissingH.Listutil".
startswith, endswith,
-- * Conversions
- split
+ -- | Note: these functions are aliases for functions
+ -- in "MissingH.Listutil".
+ join, split, trunc
) where
-import MissingH.Listutil(startswith, endswith, split)
+import MissingH.Listutil(startswith, endswith, join, split, trunc)
wschars = " \t\r\n"
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list