module Data.Text.Human.Parse
( HumanParse (..)
) where
import Data.Bool (Bool (..))
import Data.Either (Either (..))
import Data.Maybe (Maybe (..))
import Data.Text (Text)
import Data.Void (Void)
import qualified Data.Char as C
import qualified Data.Text as T
class HumanParse e a | a -> e where
parseHuman :: Text -> Either e a
instance HumanParse () Void where
parseHuman _ = Left ()
instance HumanParse e a => HumanParse e (Maybe a) where
parseHuman t = case parseHuman t of
Right a -> Right (Just a)
Left _ | isWhitespace t -> Right Nothing
Left e -> Left e
isWhitespace :: Text -> Bool
isWhitespace = T.all C.isSpace