[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:32 UTC 2010
The following commit has been merged in the master branch:
commit f591979d39d2b61cd55a38ebf4df7460fd540aec
Author: John Goerzen <jgoerzen at complete.org>
Date: Tue Oct 5 21:32:45 2004 +0100
ListUtil done
Keywords:
(jgoerzen at complete.org--projects/missingh--head--1.0--patch-14)
diff --git a/MissingH/Listutil.hs b/MissingH/Listutil.hs
index 988e5a4..4dae581 100644
--- a/MissingH/Listutil.hs
+++ b/MissingH/Listutil.hs
@@ -30,9 +30,15 @@ module MissingH.Listutil(-- * Tests
for association lists. -}
addToAL, delFromAL,
-- * Conversions
- split, join, trunc
+ split, join, trunc,
+ -- -- * Sub-List Selection
+ -- sub,
+ -- * Processing utilities
+ hPutStrLns, hGetLines
) where
import Data.List(intersperse, concat, isPrefixOf, isSuffixOf)
+import IO
+import System.IO.Unsafe
{- | Returns true if the given list starts with the specified elements;
false otherwise. (This is an alias for "Data.List.isPrefixOf".)
@@ -113,3 +119,36 @@ addToAL l key value = (key, value) : delFromAL l key
matches the given one. -}
delFromAL :: Eq key => [(key, a)] -> key -> [(key, a)]
delFromAL l key = filter (\a -> (fst a) /= key) l
+
+{- FIXME TODO: sub -}
+
+{- Given a list of strings, output a line containing each item, adding
+newlines as appropriate. The list is not expected to have newlines already.
+-}
+
+hPutStrLns :: Handle -> [String] -> IO ()
+hPutStrLns _ [] = return ()
+hPutStrLns h (x:xs) = do
+ hPutStrLn h x
+ hPutStrLns h xs
+
+{- Given a handle, returns a list of all the lines in that handle.
+Thanks to lazy evaluation, this list does not have to be read all at once.
+
+Combined with 'hPutStrLns', this can make a powerful way to develop
+filters.
+-}
+
+hGetLines :: Handle -> IO [String]
+
+hGetLines h = unsafeInterleaveIO (do
+ ieof <- hIsEOF h
+ if (ieof)
+ then return []
+ else do
+ line <- hGetLine h
+ remainder <- hGetLines h
+ return (line : remainder)
+ )
+
+
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list