Making a query parser fail

Can I somehow make a query parser fail instead of returning maybes like it does for path segments?

type Route
    = VerifyEmail String

routeParser : Parser (Maybe Route -> a) a
routeParser =
        toRoute mode oobCode =
            case mode of
                "verifyEmail" ->
                    Just <| VerifyEmail oobCode

                _ ->
        <?> Query.map2 (Maybe.map2 toRoute) (Query.string "mode") (Query.string "oobCode")
        |> (Maybe.andThen identity)

Something that would turn

routeParser : Parser (Maybe Route -> a) a


routeParser : Parser (Route -> a) a

It seems Parser.Query.string should be called Parser.Query.maybeString if the presence of the query param is optional?

It doesn’t look like it, as there is no fail operator in the API. You might have to change:

and reject the route based on the Maybe after it has been parsed. Not ideal…

Yeah, that’s what I ended up doing. I guess one could use elm/parser for more customisability.

“There’s no way to make a parser fail.”

Have you seen Parser.problem?

Edit: Oh, query parsers. Maybe problem needs to be exposed by them.

You’re referring to problem in elm/parser? I was looking for something in the elm/url package.

Edit: Sorry didn’t see your edit.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.