Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Value for QueryParameter: none #45

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

CSDUMMI
Copy link

@CSDUMMI CSDUMMI commented Mar 19, 2021

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
Copy link
Author

CSDUMMI commented Mar 20, 2021

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:

  • Either I make each QueryParameter seperately and then concat them conditionally
  • Or I use Builder.string "" "" but that leaves a = in the URL and cannot be a valid url:
    /?title=abc&content=def&keywords=ghi&=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant