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

New Value for QueryParameter: none #45

Open CSDUMMI opened 3 years ago

CSDUMMI commented 3 years ago

Many packages expose a none value, such as Html.none or Cmd.none.

Though these values do not do anything, they are useful, especially if you use if ... else or case ... of and some cases should do nothing.

I think it could be useful to introduce such a value to do nothing for the Url.Builder.QueryParameter type I write some more general functions for requests that cover several cases and I thus need to use many case ... of statements and it would make this very easy.

Currently I am working with list concats and produce code that is anything but nice on the eyes.

Implementation

With this PR I implement just this feature: Url.Builder exposes a none : QueryParameter value, which results in an empty Query string.

CSDUMMI commented 3 years ago

I have an example from my own development:

type alias Message =
    { author : String
    , title : String
    , content : String
    , keywords : String
    , response_to : Maybe Id
    , views : Int
    , id : Id
    }

query = [ Builder.string "title" message.title
             , Builder.string "content" message.content
             , Builder.string "keywords" message.keywords
             , case message.response_to of
                   Just r -> Builder.int "response_to" r
                    Nothing ->  
             ]

As you can see, I have a problem, when I get to the Nothing branch.

My fixes: