strelka-2.0.2: A simple, flexible and composable web-router

Safe HaskellNone
LanguageHaskell2010

Strelka.ParamsParsing

Contents

Description

DSL for parsing of parameters.

Synopsis

Documentation

data Params a Source #

Parser of a product of parameters.

Can be composed using the Applicative interface.

Instances

Functor Params Source # 

Methods

fmap :: (a -> b) -> Params a -> Params b #

(<$) :: a -> Params b -> Params a #

Applicative Params Source # 

Methods

pure :: a -> Params a #

(<*>) :: Params (a -> b) -> Params a -> Params b #

(*>) :: Params a -> Params b -> Params b #

(<*) :: Params a -> Params b -> Params a #

Alternative Params Source # 

Methods

empty :: Params a #

(<|>) :: Params a -> Params a -> Params a #

some :: Params a -> Params [a] #

many :: Params a -> Params [a] #

param :: Text -> Value a -> Params a Source #

Parse a param by its name using an explicit parser.

defaultParam :: DefaultValue a => Text -> Params a Source #

Parse a param by its name using the implicit default parser.

Multi-arity default param parser helpers

defaultParams2 :: (DefaultValue a, DefaultValue b) => Text -> Text -> Params (a, b) Source #

A helper abstracting over the Applicative composition of multiple defaultParam.

defaultParams3 :: (DefaultValue a, DefaultValue b, DefaultValue c) => Text -> Text -> Text -> Params (a, b, c) Source #

A helper abstracting over the Applicative composition of multiple defaultParam.

defaultParams4 :: (DefaultValue a, DefaultValue b, DefaultValue c, DefaultValue d) => Text -> Text -> Text -> Text -> Params (a, b, c, d) Source #

A helper abstracting over the Applicative composition of multiple defaultParam.

defaultParams5 :: (DefaultValue a, DefaultValue b, DefaultValue c, DefaultValue d, DefaultValue e) => Text -> Text -> Text -> Text -> Text -> Params (a, b, c, d, e) Source #

A helper abstracting over the Applicative composition of multiple defaultParam.

defaultParams6 :: (DefaultValue a, DefaultValue b, DefaultValue c, DefaultValue d, DefaultValue e, DefaultValue f) => Text -> Text -> Text -> Text -> Text -> Text -> Params (a, b, c, d, e, f) Source #

A helper abstracting over the Applicative composition of multiple defaultParam.

defaultParams7 :: (DefaultValue a, DefaultValue b, DefaultValue c, DefaultValue d, DefaultValue e, DefaultValue f, DefaultValue g) => Text -> Text -> Text -> Text -> Text -> Text -> Text -> Params (a, b, c, d, e, f, g) Source #

A helper abstracting over the Applicative composition of multiple defaultParam.

Value parsers

data Value a Source #

A parser of a parameter value.

Instances

Functor Value Source # 

Methods

fmap :: (a -> b) -> Value a -> Value b #

(<$) :: a -> Value b -> Value a #

Applicative Value Source # 

Methods

pure :: a -> Value a #

(<*>) :: Value (a -> b) -> Value a -> Value b #

(*>) :: Value a -> Value b -> Value b #

(<*) :: Value a -> Value b -> Value a #

Alternative Value Source # 

Methods

empty :: Value a #

(<|>) :: Value a -> Value a -> Value a #

some :: Value a -> Value [a] #

many :: Value a -> Value [a] #

parser :: Parser a -> Value a Source #

Lifts an Attoparsec parser into Value.

matcher :: (Text -> Either Text a) -> Value a Source #

Lifts a text-matching function into Value.

list :: Value a -> Value [a] Source #

Lifts a single value parser to the parser of a list of values.

Useful for decoding lists of values of the same name. E.g., it'll work for the both following cases:

?param[]=1&param[]=2
?param=1&param=2

In both cases the name of the parameter to look up will be "param".

maybe :: Value a -> Value (Maybe a) Source #

Lifts a single value parser to the parser of a possibly specified value.

It's useful for decoding the difference between the following two cases:

?param=value
?param

Implicit default value parsers

class DefaultValue value where Source #

Provides a default value parser.

Minimal complete definition

defaultValue

Methods

defaultValue :: Value value Source #

Instances

DefaultValue Bool Source #

Interprets all the following inputs case-insensitively: "1" or "0", "true" or "false", "yes" or "no", "y" or "n", "t" or "f". The absense of a value is interpreted as False.

DefaultValue Char Source # 
DefaultValue Double Source # 
DefaultValue Int Source # 
DefaultValue Int8 Source # 
DefaultValue Int16 Source # 
DefaultValue Int32 Source # 
DefaultValue Int64 Source # 
DefaultValue Integer Source # 
DefaultValue Word Source # 
DefaultValue Word8 Source # 
DefaultValue Word16 Source # 
DefaultValue Word32 Source # 
DefaultValue Word64 Source # 
DefaultValue ByteString Source #

Encodes the input using UTF8.

DefaultValue Text Source # 
DefaultValue String Source # 
DefaultValue Scientific Source # 
DefaultValue TimeOfDay Source # 
DefaultValue TimeZone Source # 
DefaultValue UTCTime Source # 
DefaultValue Day Source # 
DefaultValue a => DefaultValue [a] Source #

Uses list over defaultValue.

Methods

defaultValue :: Value [a] Source #

DefaultValue a => DefaultValue (Maybe a) Source #

Uses maybe over defaultValue.