module WordCount (wordCount) where

import Control.Arrow
import Data.Char (isAlphaNum, toLower)
import Data.List (group, sort)
import qualified Data.Map.Strict as Map (fromListWith, Map)

wordCount :: String -> Map.Map String Int
wordCount = Map.fromListWith (+) . wordPairs
    where wordPairs = flip zip (repeat 1) . extractWords

extractWords :: String -> [String]
extractWords = words . map toLowerCaseOrSpace
    where toLowerCaseOrSpace x = if isAlphaNum x then toLower x else ' '
