-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Add a new()
primitive to the uri
package.
#619
Comments
If I'm reading the URI syntax description correctly, it seems that at a minimum pub fn new(scheme: String) -> Uri {
Uri(
scheme: Option(scheme),
userinfo: None,
host: None,
port: None,
path: "",
query: None,
fragment: None,
)
} Your examples might then become slightly simpler. For example: uri.new("ftp")
|> uri.to_string
|> should.equal("ftp:") Arguably, defaulting |
That sounds sensible to me! That said, given we're unlikely to get the builder API is there still a use case for this function? |
Probably not. |
Even if we do not have builders, would it not be valuable to still have a function (or perhaps even a constant Referring back to this usage: let uri = Uri(..uri.new(), scheme: "http", host: "localhost") |
OK, sounds good. |
Inspired by the
request.new()
andresponse.new()
functions from thegleam_http
package, and while working withUri
s, I thought that it would also be a good idea to be able to do the same withUri
.Provisionally, the implementation of the function would look as follows:
This would create a completely bare
Uri
object that the developer could then go ahead and build on top of. I have created a related issue here that would implement 'builder' primitives to set fields on theUri
object. Coupled, these primitives would create a really nice pattern for building out aUri
, but even without those 'setter' primitives being present yet, the developer could still utilise this implementation ofnew()
as follows:This primitive would make cases like the following taken from
uri_test.gleam
more concise:allowing them to be switched out for:
and coupled with the 'setter' primitive proposal mentioned earlier (here), if that proposal were to be implemented:
If okay'd, I'd be happy to go ahead and implement this myself.
The text was updated successfully, but these errors were encountered: