Created
August 25, 2014 10:41
-
-
Save MarcoSero/7ad9ddc369505de3a7ba to your computer and use it in GitHub Desktop.
Haskell case additions
This file contains hidden or 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
separatedWords :: String -> [String] | |
separatedWords = filter (not . any isSpace) . groupBy ((==) `on` isSpace) | |
toCamel :: String -> String | |
toCamel = foldl (\acc x -> acc ++ [(if null acc then (head x) else (toUpper $ head x))] ++ (tail x)) [] . separatedWords . map (toLower) | |
toSnake :: String -> String | |
toSnake = foldr (\x acc -> x ++ (if null acc then "" else "_") ++ acc) [] . separatedWords . map (toLower) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know if it still works for you, but here you are a more readable but still in-liner version of your functions. 😉