packages feed

devforms-0.2.0.2 / src / ParsedInteger.hs

module ParsedInteger (ParsedInteger, parseWithBounds, parsedToInteger, IntegerBoundError (..))wherenewtype ParsedInteger = ParsedInteger Integerdata IntegerBoundError = IntegerOutOfBounds deriving (Show)parseWithBounds :: Maybe Integer -> Maybe Integer -> Integer -> Either IntegerBoundError ParsedIntegerparseWithBounds (Just lowerBoundInclusive) (Just upperBoundInclusive) n =    if lowerBoundInclusive <= n && upperBoundInclusive >= n        then pure $ ParsedInteger n        else Left IntegerOutOfBoundsparseWithBounds (Just lowerBoundInclusive) Nothing n =    if lowerBoundInclusive <= n        then pure $ ParsedInteger n        else Left IntegerOutOfBoundsparseWithBounds Nothing (Just upperBoundInclusive) n =    if upperBoundInclusive >= n        then pure $ ParsedInteger n        else Left IntegerOutOfBoundsparseWithBounds Nothing Nothing n = Right $ ParsedInteger nparsedToInteger :: ParsedInteger -> IntegerparsedToInteger (ParsedInteger n) = n