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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to match the example, you'd want
toUpper a : map toLower b
inucFirst
, since it changes"VRI"
to"Vri"
.or
ucFirst = zipWith ($) (toUpper : repeat toLower)