Skip to content

Instantly share code, notes, and snippets.

@dyokomizo
Created April 20, 2012 11:27
Show Gist options
  • Save dyokomizo/2427907 to your computer and use it in GitHub Desktop.
Save dyokomizo/2427907 to your computer and use it in GitHub Desktop.
Linefy
-- 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
@dyokomizo
Copy link
Author

Uncompiled and untested :)

Took me 5 minutes to write it:

  • 1 minute for specification (i.e. type signatures)
  • 4 minutes for implementation.

I estimated 10 minutes, considering testing, so it seems to be in the right ballpark.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment