module Exercises where import Data.Array (filter) import Data.Char (toLower, toUpper) import Data.Maybe (Maybe(..)) import Data.String (fromCharArray, toCharArray, uncons) import Prelude -- 2 filterUppercase :: String -> String filterUppercase s = fromCharArray $ filter (\x -> toLower x /= x) (toCharArray s) -- 3 capitalize :: String -> String capitalize s = maybeCapitalize $ uncons s where maybeCapitalize Nothing = "" maybeCapitalize (Just {head, tail}) = (fromCharArray $ [ toUpper head ]) <> tail -- 4 capitalize' :: String -> String capitalize' s = fromCharArray $ map toUpper $ toCharArray s -- 5 firstLetter :: String -> Maybe Char firstLetter = firstLetter' <<< uncons where firstLetter' Nothing = Nothing firstLetter' (Just {head, tail}) = Just $ toUpper head