{-# 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
  Int
i <- forall a. Read a => String -> Maybe a
readMaybe String
s
  forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ Int
i forall a. Ord a => a -> a -> Bool
>= Int
0
  forall a. a -> Maybe a
Just Int
i