Data.Intertwine.Route
- Package
- purescript-intertwine
- Repository
- collegevine/purescript-intertwine
#IsRoute Source
class IsRoute r where
This class abstracts the idea of the "route" data type, making it possible for the primitive in this module to work with data types from other libraries.
Members
routeEmpty :: r
routeSegments :: Lens' r (Array String)
routeQueryString :: Lens' r (Object String)
Instances
#parseRoute Source
parseRoute :: forall route a. IsRoute route => RoutesDef route a -> route -> Maybe a
#printRoute Source
printRoute :: forall route a. IsRoute route => RoutesDef route a -> a -> Maybe route
#segValue' Source
segValue' :: forall route a. IsRoute route => (a -> String) -> (String -> Maybe a) -> RoutesDef route a
A value of the given type as URL segment. During printing, the printer outputs the value as a URL segment, using the provided printing function to convert it to a string. During parsing, the parser consumes a URL segment and tries to parse it into a value of the given type using the provided parsing function.
#segValue Source
segValue :: forall route a. IsRoute route => PathPiece a => RoutesDef route a
A value of the given type as URL segment. During printing, the printer
outputs the value as a URL segment, using the PathPiece
instance to
convert it to a string. During parsing, the parser consumes a URL segment
and tries to parse it into a value of the given type using the PathPiece
instance.
#constValue Source
constValue :: forall route a. Eq a => a -> RoutesDef route a
A primitive that encodes a constant value. During printing, the printer
succeeds iff the value beign printed is equal to theValue
, otherwise
fails. During parsing, the parser returns theValue
without consuming any
input.
#query' Source
query' :: forall route a. IsRoute route => (a -> String) -> (String -> Maybe a) -> String -> RoutesDef route (Maybe a)
QueryString value. During printing adds the printed value (converted via the given printing function) to the QueryString under given key. During parsing, looks up the value in the QueryString and attempts to parse it with the given parsing function.
Re-exports from Data.Intertwine.Route.PathPiece
#PathPiece Source
class PathPiece a where
This class makes a type suitable for participating in route printing/parsing - i.e. to be the type of path segments and querystring parameters.
Members
toPathSegment :: a -> String
fromPathSegment :: String -> Maybe a
Instances
Re-exports from Data.Intertwine.Syntax
#(<|||>) Source
Operator alias for Data.Intertwine.Syntax.alt (left-associative / precedence 2)
Combines two printers/parsers of the same type in a way that first attempts the left one, and if it fails, falls back to the right.
#(<|:|>) Source
Operator alias for Data.Intertwine.Syntax.injectConstructor (right-associative / precedence 5)
Binds a constructor, whose name is encoded in the Ctor
value, to the
given parser/printer.
For example:
data T = A String | B (Maybe Int)
syntax =
(Ctor::Ctor "A") <|:|> value
<|||> (Ctor::Ctor "B") <|:|> query "id"
#(<|*|>) Source
Operator alias for Data.Intertwine.Syntax.synApply (right-associative / precedence 5)
Combines two printers/parsers together, iyelding a printer/parser that can print/parse a tuple of the two combined values.
a :: syntax a
b :: syntax b
a <|*|> b :: syntax (a, b)
#(<|$|>) Source
Operator alias for Data.Intertwine.Syntax.synInject (right-associative / precedence 5)
Injects an Iso
into a printer/parser on the right side, producing a
printer/parser of the type that is left type of the Iso
.
i :: Iso a (b, (c, d))
p :: syntax (b, (c, d))
i <|$|> p :: syntax a
#(*|>) Source
Operator alias for Data.Intertwine.Syntax.dropUnitLeft (right-associative / precedence 5)
Combines a printer/parser that consumes/returns a unit with another
printer/parser in a way that the unit is dropped instead of becoming part
of a tuple, as it would with <|*|>
u :: syntax Unit
a :: syntax a
u *|> a :: syntax a