Open CSDUMMI opened 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:
Builder.string "" ""
but that leaves a =
in the URL and cannot be a valid url:
/?title=abc&content=def&keywords=ghi&=
Many packages expose a none value, such as
Html.none
orCmd.none
.Though these values do not do anything, they are useful, especially if you use
if ... else
orcase ... 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.