packages feed

devforms-0.1.2.0 / src / ParsedInteger.hs

module ParsedInteger (ParsedInteger, parseWithBounds, parsedToInteger)wherenewtype ParsedInteger = ParsedInteger IntegerparseWithBounds :: Maybe Integer -> Maybe Integer -> Integer -> Either Text ParsedIntegerparseWithBounds (Just lowerBoundInclusive) (Just upperBoundInclusive) n =    if lowerBoundInclusive <= n && upperBoundInclusive >= n        then pure $ ParsedInteger n        else Left "Integer is outside bounds"parseWithBounds (Just lowerBoundInclusive) Nothing n =    if lowerBoundInclusive <= n        then pure $ ParsedInteger n        else Left "Integer is out of bounds"parseWithBounds Nothing (Just upperBoundInclusive) n =    if upperBoundInclusive >= n        then pure $ ParsedInteger n        else Left "Integer is out of bounds"parseWithBounds Nothing Nothing n = Right $ ParsedInteger nparsedToInteger :: ParsedInteger -> IntegerparsedToInteger (ParsedInteger n) = n