We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ab4c9ed + 655865d commit 1c8b522Copy full SHA for 1c8b522
src/Routing/Match.purs
@@ -176,3 +176,12 @@ eitherMatch (Match r2eab) = Match $ \r ->
176
case eit of
177
Left _ -> invalid $ free $ Fail "Nested check failed"
178
Right res -> pure $ Tuple rs res
179
+
180
+-- | useful for matching optional params at the end of a path
181
+-- | ```
182
+-- | optParams = maybe M.empty id <$> optionalMatch params <* end
183
+-- | runMatch (lit "path" *> optParams) (parse id "path/?a=1")
184
+-- | -- (Right (fromFoldable [(Tuple "a" "1")]))
185
186
+optionalMatch :: forall a. Match a -> Match (Maybe a)
187
+optionalMatch (Match fn) = Match (\route -> unV (const $ pure (Tuple route Nothing)) (pure <<< map Just) $ fn route)
0 commit comments