Routing.Match
- Package
- purescript-routing
- Repository
- slamdata/purescript-routing
#eitherMatch Source
eitherMatch :: forall b a. Match (Either a b) -> Match bif 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))
#nonempty Source
nonempty :: Match NonEmptyStringMatches a non-empty string.
#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")]))
Re-exports from Routing.Match.Class
#MatchClass Source
class (Alternative f) <= MatchClass f whereMembers
lit :: String -> f Unitstr :: f Stringstrmatches any path string component. For example,strmatches/fooas"foo".param :: String -> f Stringparam pmatches a parameter assignmentq=vwithin a query block. For example,param "q"matches/?q=a&r=bas"a".params :: f (Map String String)paramsmatches an entire query block. For exmaple,paramsmatches/?q=a&r=bas the map{q : "a", r : "b"}. Note thatlit "foo" *> paramsdoes not match/foo, since a query component is required.num :: f Numbernummatches any numerical path component.int :: f Intintmatches any integer path component.bool :: f Booleanboolmatches any boolean path component.end :: f Unitendmatches the end of a route.fail :: forall a. String -> f a
#root Source
root :: forall f. MatchClass f => f UnitMatches a leading slash.
lit xwill match exactly the path componentx. For example,lit "x"matches/x.