Skip to content

Instantly share code, notes, and snippets.

@codebje
Created October 19, 2016 00:29
Show Gist options
  • Save codebje/9c0121e8cb744d5c57d856beef94489d to your computer and use it in GitHub Desktop.
Save codebje/9c0121e8cb744d5c57d856beef94489d to your computer and use it in GitHub Desktop.
#!/usr/local/bin/stack runghc
import Data.Char (toUpper)
import Data.List (uncons)
ucFirst :: String -> String
ucFirst = maybe "" (\(a,b) -> toUpper a : b) . uncons
process :: String -> [String]
process s =
let slug = mconcat $ map ucFirst $ words s
in [ "<dt runat=\"server\" id=\"dt" ++ slug ++ "\">" ++ s ++ "</dt>"
, "<dd runat=\"server\" id=\"dd" ++ slug ++ "\"></dd>", ""]
main :: IO ()
main = do
input <- getContents
mapM_ putStrLn $ (process =<<) $ lines input
@rampion
Copy link

rampion commented Oct 19, 2016

to match the example, you'd want toUpper a : map toLower b in ucFirst, since it changes "VRI" to "Vri".

or ucFirst = zipWith ($) (toUpper : repeat toLower)

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