Created
April 20, 2012 11:27
-
-
Save dyokomizo/2427907 to your computer and use it in GitHub Desktop.
Linefy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- An implementation of http://blog.8thlight.com/uncle-bob/2012/04/20/Why-Is-Estimating-So-Hard.html | |
type Size = Int | |
type Word = String | |
type Line = String | |
linefy :: Size -> [Word] -> [Line] | |
linefy s ws = go [] ws | |
where go [] (w:ws) | length w > s = [] | |
| otherwise = go [w] ws | |
go (l:ls) (w:ws) | length w > s = [] | |
| length w + 1 + length l > s = go (w:l:ls) ws | |
| otherwise = go ((l ++ " " ++ w):ls) ws | |
go ls [] = reverse ls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uncompiled and untested :)
Took me 5 minutes to write it:
I estimated 10 minutes, considering testing, so it seems to be in the right ballpark.