Module

Routing.Match

Package
purescript-routing
Repository
slamdata/purescript-routing

#list Source

list :: forall a. Match a -> Match (List a)

Matches list of matchers. Useful when argument can easy fail (not str) returns Match Nil if no matches

#runMatch Source

runMatch :: forall a. Match a -> Route -> Either String a

#eitherMatch Source

eitherMatch :: forall b a. Match (Either a b) -> Match b

if we match something that can fail then we have to match Either a b. This function converts matching on such sum to matching on right subpart. Matching on left branch fails. i.e.

data Sort = Asc | Desc
sortOfString :: String -> Either String Sort
sortOfString "asc" = Right Asc
sortOfString "desc" = Right Desc
sortOfString _ = Left "incorrect sort"

newtype Routing = Routing Sort
routes :: Match Routing
routes = (pure Routing) <*> (eitherMatch (sortOfString <$> var))

#optionalMatch Source

optionalMatch :: forall a. Match a -> Match (Maybe a)

useful for matching optional params at the end of a path

optParams = maybe M.empty id <$> optionalMatch params <* end
runMatch (lit "path" *> optParams) (parse id "path/?a=1")
-- (Right (fromFoldable [(Tuple "a" "1")]))