servant-0.20.3.0: A family of combinators for defining webservices APIs

Safe Haskell | None
Language | Haskell2010

Servant.API.Range

Synopsis

- data Range (min :: Nat) (max :: Nat)
- unsafeRange :: forall (min :: Nat) (max :: Nat). Natural -> Range min max
- mkRange :: forall (min :: Nat) (max :: Nat). (KnownNat min, KnownNat max) => Natural -> Maybe (Range min max)

# Documentation

data Range (min :: Nat) (max :: Nat) Source #

A newtype wrapper around `Natural` that ensures the value is within a given range.

Example:

    >>> :{
      let validRange = mkRange 5 :: Maybe (Range 1 10)
      in case validRange of
           Just r  -> "Valid range: " ++ show (unRange r)
           Nothing -> "Invalid range"
    :}
    "Valid range: 5"

    >>> :{
      let invalidRange = mkRange 15 :: Maybe (Range 1 10)
      in case invalidRange of
           Just r  -> "Valid range: " ++ show (unRange r)
           Nothing -> "Invalid range"
    :}
    "Invalid range"

    >>> decode "5" :: Maybe (Range 1 10)
    Just (MkRange {unRange = 5})

    >>> decode "15" :: Maybe (Range 1 10)
    Nothing

#### Instances

Instances details

(KnownNat min, KnownNat max) => FromJSON (Range min max) Source # |
Instance details Defined in Servant.API.Range Methods parseJSON :: Value -> Parser (Range min max) Source # parseJSONList :: Value -> Parser [Range min max] Source # omittedField :: Maybe (Range min max) Source #
ToJSON (Range min max) Source # |
Instance details Defined in Servant.API.Range Methods toJSON :: Range min max -> Value Source # toEncoding :: Range min max -> Encoding Source # toJSONList :: [Range min max] -> Value Source # toEncodingList :: [Range min max] -> Encoding Source # omitField :: Range min max -> Bool Source #
(KnownNat min, KnownNat max) => Bounded (Range min max) Source # |
Instance details Defined in Servant.API.Range Methods minBound :: Range min max Source # maxBound :: Range min max Source #
Generic (Range min max) Source # |

Instance details

Defined in Servant.API.Range

Associated Types

type Rep (Range min max) |
Instance details Defined in Servant.API.Range type Rep (Range min max) = D1 ('MetaData "Range" "Servant.API.Range" "servant-0.20.3.0-FHJyKhVqWFv2rTftFmLybU" 'True) (C1 ('MetaCons "MkRange" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRange") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Natural)))

Methods

from :: Range min max -> Rep (Range min max) x Source #

to :: Rep (Range min max) x -> Range min max Source #

Ix (Range min max) Source # |

Instance details

Defined in Servant.API.Range

Methods

range :: (Range min max, Range min max) -> [Range min max] Source #

index :: (Range min max, Range min max) -> Range min max -> Int Source #

unsafeIndex :: (Range min max, Range min max) -> Range min max -> Int Source #

inRange :: (Range min max, Range min max) -> Range min max -> Bool Source #

rangeSize :: (Range min max, Range min max) -> Int Source #

unsafeRangeSize :: (Range min max, Range min max) -> Int Source #

Show (Range min max) Source # |
Instance details Defined in Servant.API.Range Methods showsPrec :: Int -> Range min max -> ShowS Source # show :: Range min max -> String Source # showList :: [Range min max] -> ShowS Source #
Eq (Range min max) Source # |
Instance details Defined in Servant.API.Range Methods (==) :: Range min max -> Range min max -> Bool Source # (/=) :: Range min max -> Range min max -> Bool Source #
Ord (Range min max) Source # |

Instance details

Defined in Servant.API.Range

Methods

compare :: Range min max -> Range min max -> Ordering Source #

(<) :: Range min max -> Range min max -> Bool Source #

(<=) :: Range min max -> Range min max -> Bool Source #

(>) :: Range min max -> Range min max -> Bool Source #

(>=) :: Range min max -> Range min max -> Bool Source #

max :: Range min max -> Range min max -> Range min max Source #

min :: Range min max -> Range min max -> Range min max Source #

(KnownNat min, KnownNat max) => FromHttpApiData (Range min max) Source # |
Instance details Defined in Servant.API.Range Methods parseUrlPiece :: Text -> Either Text (Range min max) Source # parseHeader :: ByteString -> Either Text (Range min max) Source # parseQueryParam :: Text -> Either Text (Range min max) Source #
ToHttpApiData (Range min max) Source # |
Instance details Defined in Servant.API.Range Methods toUrlPiece :: Range min max -> Text Source # toEncodedUrlPiece :: Range min max -> Builder Source # toHeader :: Range min max -> ByteString Source # toQueryParam :: Range min max -> Text Source # toEncodedQueryParam :: Range min max -> Builder Source #
type Rep (Range min max) Source # |
Instance details Defined in Servant.API.Range type Rep (Range min max) = D1 ('MetaData "Range" "Servant.API.Range" "servant-0.20.3.0-FHJyKhVqWFv2rTftFmLybU" 'True) (C1 ('MetaCons "MkRange" 'PrefixI 'True) (S1 ('MetaSel ('Just "unRange") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Natural)))

unsafeRange :: forall (min :: Nat) (max :: Nat). Natural -> Range min max Source #

mkRange :: forall (min :: Nat) (max :: Nat). (KnownNat min, KnownNat max) => Natural -> Maybe (Range min max) Source #