Sha256: 85e7a8ae6f347446def1d11a63c92e208b28b46fd4520a8560be3935001bb654
Contents?: true
Size: 794 Bytes
Versions: 50
Compression:
Stored size: 794 Bytes
Contents
module PhoneNumber ( phoneNumber ) where import Prelude ((==), (<), (>>=), (&&), ($), otherwise) import Data.Char.Unicode (isDigit) import Data.Array (filter, head, tail, length, (!!)) import Data.String (toCharArray, fromCharArray) import Data.Maybe (Maybe(..), fromMaybe) clean :: String -> Maybe (Array Char) clean input = go where go | len == 10 = Just digits | len == 11 && head digits == Just '1' = tail digits | otherwise = Nothing digits = filter isDigit $ toCharArray input len = length digits check:: Array Char -> Maybe String check input | input !! 0 < Just '2' = Nothing | input !! 3 < Just '2' = Nothing | otherwise = Just $ fromCharArray input phoneNumber :: String -> String phoneNumber input = fromMaybe "None" (clean input >>= check)
Version data entries
50 entries across 50 versions & 1 rubygems