From 68f765ffe71a8ed9bb5927e29d3349f2504b71e2 Mon Sep 17 00:00:00 2001 From: Diemo Gebhardt Date: Tue, 30 Jul 2024 08:17:51 +0100 Subject: [PATCH] Add Uri.empty constant representing an empty URI --- src/gleam/uri.gleam | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam index b64a1c09..8389b20b 100644 --- a/src/gleam/uri.gleam +++ b/src/gleam/uri.gleam @@ -28,6 +28,48 @@ pub type Uri { ) } +/// A constant representing an empty URI, useful as a starting point for constructing +/// URIs with minimal boilerplate. +/// +/// ## Examples +/// +/// ```gleam +/// let empty_uri = Uri.empty +/// // -> Uri( +/// // scheme: None, +/// // userinfo: None, +/// // host: None, +/// // port: None, +/// // path: "", +/// // query: None, +/// // fragment: None, +/// // ) +/// ``` +/// +/// ```gleam +/// // 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, +/// // ) +/// ``` +/// +pub const empty = Uri( + scheme: None, + userinfo: None, + host: None, + port: None, + path: "", + query: None, + fragment: None, +) + /// Parses a compliant URI string into the `Uri` Type. /// If the string is not a valid URI string then an error is returned. ///