{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} module Network.HTTP.Client.Util ( readPositiveInt ) where import Text.Read (readMaybe) import Control.Monad (guard) -- | Read a positive 'Int', accounting for overflow readPositiveInt :: String -> Maybe Int readPositiveInt :: String -> Maybe Int readPositiveInt String s = do i <- String -> Maybe Int forall a. Read a => String -> Maybe a readMaybe String s guard $ i >= 0 Just i