evancz / url-parser

Parse URLs into nicely structured data
http://package.elm-lang.org/packages/evancz/url-parser/latest/
BSD 3-Clause "New" or "Revised" License
114 stars 29 forks source link

Improper semantics with multiple query parameters and (<?>) #24

Closed ckoster22 closed 7 years ago

ckoster22 commented 7 years ago

Below is an elm-repl example simulating a user navigating to a URL like http://localhost/blog?search=cats&order=desc.

> maybesToString m1 m2 = \
|   case (m1, m2) of \
|     (Just search, Just order) -> search ++ " " ++ order \
|     _ -> "No match"
<function> : Maybe.Maybe String -> Maybe.Maybe String -> String

> parsePath (oneOf [map maybesToString (s "blog" <?> stringParam "search" <?> stringParam "order")]) (Location "" "" "" "" "" "" "/blog" "?search=cats&order=desc" "" "" "")
Just "cats desc" : Maybe.Maybe String

(</>) and (<?>) are available but (<&>) doesn't exist. As such I am forced to chain multiple (<?>) functions in this part: (s "blog" <?> stringParam "search" <?> stringParam "order").

The <?> followed by another <?> doesn't read correctly since my URL is not http://localhost/blog?search=cats?order=desc. I expected to find <&> so that the code above could read like this: (s "blog" <?> stringParam "search" <&> stringParam "order")

process-bot commented 7 years ago

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

evancz commented 7 years ago

I don't think it makes sense to add a (<&>) operator. I assume you are suggesting it has the same type as (<?>) which would mean you could use them interchangeably. I think that is more confusing than using <?> multiple times personally.

Maybe you are suggesting something else, but there are no types shown here, so I don't know. Overall, I don't think it makes sense to add <&>.

ckoster22 commented 7 years ago

You're correct that I'm suggesting having an (<&>) operator, if not some documentation on how to use multiple query parameters, because it wasn't apparent to me until I read the source that I needed to use (<?>) multiple times.

Whether the two operators can used interchangeably is more of an implementation concern, IMO. I'm commenting on the semantics of those operators.

s corresponds to any string </> corresponds to a forward slash <?> corresponds to the start of a query string <?> also corresponds to a query string key/value separator?

Rather, <&> makes perfect sense to me to correspond with the real "&" query string parameter separator.