Skip to content

Instantly share code, notes, and snippets.

@codebje
Created Oct 19, 2016
Embed
What would you like to do?
#!/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