elm / url

Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
https://package.elm-lang.org/packages/elm/url/latest/
BSD 3-Clause "New" or "Revised" License
74 stars 43 forks source link

First argument to `custom` is not used any more. Caused confusion among some users. #6

Closed wking-io closed 6 years ago

wking-io commented 6 years ago

Hey!

I was informed that the Url Parser is being moved to this repository and to check and see if this issue still exists: https://github.com/evancz/url-parser/issues/51

It does! Some users in the #beginner thread mentioned that had no idea the purpose of the first argument to the custom function. I took a look and it used to be used for error messages, but those have since been removed and the argument tipe is not used in the function. Here is an example of what the current use cases are in the documentation and what it would look like without the unused argument.


-- The int example in the docs. The confusion lay with the "NUMBER" argument.

int : Parser (Int -> a) a
int =
    custom "NUMBER" String.toInt

-- The int example without the argument

int : Parser (Int -> a) a
int =
    custom String.toInt

-- The CSS example in the docs. It is "CSS_FILE" here

css : Parser (String -> a) a
    css =
      custom "CSS_FILE" <| \segment ->
        if String.endsWith ".css" segment then
          Just segment
        else
          Nothing

-- The CSS example without the argument

css : Parser (String -> a) a
css =
    custom 
        (\segment ->
            if String.endsWith ".css" segment then
              Just segment
            else
              Nothing
        )
evancz commented 6 years ago

It may be used at a later time, so I would like to keep it in the API to avoid breaking changes.