Sha256: 8df7d20741401b74e6b9629a10924ec3653f4f38d244e7cf035cb08a4c3cefc7
Contents?: true
Size: 938 Bytes
Versions: 83
Compression:
Stored size: 938 Bytes
Contents
module Phone (number, areaCode, prettyPrint) where import Data.Char (isDigit) number :: String -> Maybe String number input | len == 10 = Just digits | len == 11 && head digits == '1' = Just $ tail digits | otherwise = Nothing where digits = filter isDigit input len = length digits parts :: String -> Maybe (String, String, String) parts input = case number input of Nothing -> Nothing Just digits -> Just (ac, exchange, subscriber) where (ac, exchangeSubscriber) = splitAt 3 digits (exchange, subscriber) = splitAt 3 exchangeSubscriber areaCode :: String -> Maybe String areaCode input = case parts input of Just (ac, _, _) -> Just ac Nothing -> Nothing prettyPrint :: String -> Maybe String prettyPrint input = case parts input of Just (ac, exchange, subscriber) -> Just $ "(" ++ ac ++ ") " ++ exchange ++ "-" ++ subscriber Nothing -> Nothing
Version data entries
83 entries across 83 versions & 1 rubygems