So have this
type DocName = FilePath
type Line = (Int,String)
type Document = [Line]
splitLines :: String -> Document
splitLines [] = []
splitLines str = zip [0..(length listStr)] listStr
where
listStr = [getLine] ++ map snd (splitLines getRest)
getLine = (takeWhile (/='\n') str)
getRest = (dropWhile (=='\n') (dropWhile (/='\n') str))
works ok except i guess i need empty lines as well.
splitLines "test\nthis\nstring\n" should be
[(0,"test"),(1,"this"),(2,"string"),(3,"")]
Not exactly sure how i could do this. Any ideas? Do i need to rewrite it with something else?
Should i use a high order function like foldr? Thanks.
Figured it out finally thanks.
splitLines :: String -> Document
splitLines "" = [(0,"")]
splitLines str = zip [0..(length listStr)] listStr
where
listStr = [getLine] ++ map snd (splitLines getRest)
getLine = takeWhile (/='\n') str
getRest = tail (dropWhile (/='\n') str)