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

Add Uri.empty constant representing an empty URI, equivalent to "" #798

Merged
merged 7 commits into from
Feb 11, 2025

Conversation

diemogebhardt
Copy link
Contributor

This PR is regarding issues #619 and #618. More specifically: #619 (comment).

It introduces a Uri.empty constant, useful as a starting point for constructing URIs with minimal boilerplate.

Examples

let empty_uri = Uri.empty

// -> Uri(
//   scheme: None,
//   userinfo: None,
//   host: None,
//   port: None,
//   path: "",
//   query: None,
//   fragment: None,
// )
// Create a URI by overriding only the needed fields:

let localhost_uri = Uri(..Uri.empty, scheme: Some("http"), host: Some("localhost"))

// -> Uri(
//   scheme: Some("http"),
//   userinfo: None,
//   host: Some("localhost"),
//   port: None,
//   path: "",
//   query: None,
//   fragment: None,
// )

@diemogebhardt diemogebhardt force-pushed the uri-empty branch 2 times, most recently from e29ec88 to 66ebc53 Compare February 4, 2025 07:33
@lpil
Copy link
Member

lpil commented Feb 4, 2025

Is new the right name here? What does an empty URI mean?

@diemogebhardt
Copy link
Contributor Author

diemogebhardt commented Feb 4, 2025

Is new the right name here? What does an empty URI mean?

As string, this constant represents "". What is the proper term when picturing a "" string, <a href="">, a URI/URL form field or a browser address bar without any content?

Uri.empty or Uri.blank make sense to me as a non-native speaker. The Android API has the concept of an empty URI: https://developer.android.com/reference/android/net/Uri#EMPTY

Uri.default? It's not a URI containing default values.

Uri.new? We are not really constructing anything. But as a concept it is known and might make sense. Would you prefer it to be implemented as a Uri.new() function?

@lpil
Copy link
Member

lpil commented Feb 5, 2025

Great, that's very helpful thank you. Let's add that 'equivalent to ""', like in the Android docs there, I think that is a lot clearer.

Could you remove one of the two examples please, it's quite verbose showing the same thing twice, and the HTML documentation and the link to the code already show the structure.

@diemogebhardt diemogebhardt changed the title Introduce a Uri.empty constant Introduce a Uri.empty constant representing an empty URI, equivalent to "" Feb 9, 2025
@diemogebhardt diemogebhardt force-pushed the uri-empty branch 3 times, most recently from da99223 to 8632326 Compare February 9, 2025 11:13
@diemogebhardt diemogebhardt changed the title Introduce a Uri.empty constant representing an empty URI, equivalent to "" Add Uri.empty constant representing an empty URI, equivalent to "" Feb 9, 2025
@diemogebhardt
Copy link
Contributor Author

Ok, done! :)

Updated one example to use the Uri.empty.

And changed two examples to use secure https://example.com instead of insecure http://example.com. They are just examples, yet it doesn't hurt to show best practices.

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@lpil lpil merged commit f690a8e into gleam-lang:main Feb 11, 2025
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.

2 participants