Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wrapText text width =
- unlines $ reverse $ makeReversedParagraph(words text) width [""]
- appendWordToLine [] word = word
- appendWordToLine line word = line ++ " " ++ word
- appendWordToReversedParagraph :: [String] -> String -> Int -> [String]
- appendWordToReversedParagraph (x:xs) word width
- | length word <= width =
- if length (x ++ word) + 1 <= width
- then [appendWordToLine x word] ++ xs
- else [word] ++ x:xs
- | otherwise = [ drop width word ] ++ [ take width word ] ++ x:xs
- makeReversedParagraph :: [String] -> Int -> [String] -> [String]
- makeReversedParagraph [] _ par = par
- makeReversedParagraph (x:xs) width par = makeReversedParagraph xs width (appendWordToReversedParagraph par x width)
- main = do
- let text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."
- putStr(wrapText text 40)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement