[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:21 UTC 2010


The following commit has been merged in the master branch:
commit e507a9554667297ca1d2f4f6e018b794baebeb36
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Oct 5 19:55:39 2004 +0100

    Added startswith, endswith
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--1.0--patch-6)

diff --git a/MissingH/Strutil.hs b/MissingH/Strutil.hs
index 1a34c36..352a02c 100644
--- a/MissingH/Strutil.hs
+++ b/MissingH/Strutil.hs
@@ -58,3 +58,21 @@ lstrip s = case s of
 rstrip :: String -> String
 rstrip = reverse . lstrip . reverse
 
+-- | Returns true if the given list starts with the specified elements;
+-- false otherwise.
+--
+-- Example: startswith "He" "Hello" -> True
+
+startswith :: Eq a => [a] -> [a] -> Bool
+startswith [] _ = True
+startswith _ [] = False
+startswith (x:xs) (l:ls) =
+    if (x == l) then startswith xs ls
+    else False
+
+-- | Returns true if the given list ends with the specified elements;
+-- false otherwise.
+--
+-- Example: endswith "lo" "Hello" -> True
+endswith :: Eq a => [a] -> [a] -> Bool
+endswith x l = startswith (reverse x) (reverse l)

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list