module ToUpperFirst where import Data.Char import Data.List mapcap :: String -> String mapcap = concat . intersperse " " . fmap (\(l:ls) -> (toUpper l):ls) . words
- module ToUpperFirst where
import Data.Char- import Data.Char
- import Data.List
toUpperFirst "" = ""toUpperFirst (x : xs) = (toUpper x) : xs- mapcap :: String -> String
- mapcap = concat . intersperse " " . fmap (\(l:ls) -> (toUpper l):ls) . words
module ExampleSpec where -- Tests can be written using Hspec http://hspec.github.io/ -- Replace this with your own tests. import Test.Hspec import ToUpperFirst -- `spec` of type `Spec` must exist spec :: Spec spec = do describe "mapcap" $ do it "capitalizes first character of each word" $ do mapcap "" `shouldBe` "" mapcap "finn the human" `shouldBe` "Finn The Human" mapcap "alice the wolf" `shouldBe` "Alice The Wolf" -- the following line is optional for 8.2 main = hspec spec
- module ExampleSpec where
- -- Tests can be written using Hspec http://hspec.github.io/
- -- Replace this with your own tests.
- import Test.Hspec
- import ToUpperFirst
- -- `spec` of type `Spec` must exist
- spec :: Spec
- spec = do
describe "toUpperFirst" $ doit "capitalize first character of a string" $ dotoUpperFirst "" `shouldBe` ""toUpperFirst "finn the human" `shouldBe` "Finn the human"toUpperFirst "alice" `shouldBe` "Alice"- describe "mapcap" $ do
- it "capitalizes first character of each word" $ do
- mapcap "" `shouldBe` ""
- mapcap "finn the human" `shouldBe` "Finn The Human"
- mapcap "alice the wolf" `shouldBe` "Alice The Wolf"
- -- the following line is optional for 8.2
- main = hspec spec