re: Daily Challenge #95 - CamelCase Method VIEW POST

FULL DISCUSSION
 

Haskell

import Data.Char

(|>) = flip ($)

split :: String -> [String]
split [] = [""]
split (character : characters)
    | character == ' ' = "" : rest
    | otherwise = (character : head rest) : tail rest
    where rest = split characters

uppercase :: String -> String
uppercase string =
    map toUpper string

lowercase :: String -> String
lowercase string =
    map toLower string

capitalize :: String -> String
capitalize string =
    uppercase firstCharacter ++ lowercase remainingCharacters
    where
        firstCharacter :: String
        firstCharacter = take 1 string

        remainingCharacters :: String
        remainingCharacters = drop 1 string

join :: [String] -> String
join strings =
    foldl (++) "" strings

camelcase :: String -> String
camelcase string =
    string
        |> split
        |> map capitalize
        |> join

main :: IO ()
main = do
    print $ camelcase "hello case"      -- HelloCase
    print $ camelcase "camel case word" -- CamelCaseWord

Source-Code

Available on repl.it.

code of conduct - report abuse