aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gleam/pair.gleam14
-rw-r--r--test/gleam/pair_test.gleam5
2 files changed, 19 insertions, 0 deletions
diff --git a/src/gleam/pair.gleam b/src/gleam/pair.gleam
index e9b99fd..894e6a8 100644
--- a/src/gleam/pair.gleam
+++ b/src/gleam/pair.gleam
@@ -69,3 +69,17 @@ pub fn map_second(of pair: #(a, b), with fun: fn(b) -> c) -> #(a, c) {
let #(a, b) = pair
#(a, fun(b))
}
+
+/// Returns a new pair with the given elements. This can also be done using the dedicated
+/// syntax instead: `new(1, 2) == #(1, 2)`.
+///
+/// ## Examples
+///
+/// ```gleam
+/// > new(1, 2)
+/// #(1, 2)
+/// ```
+///
+pub fn new(first: a, second: b) -> #(a, b) {
+ #(first, second)
+}
diff --git a/test/gleam/pair_test.gleam b/test/gleam/pair_test.gleam
index 770f7b7..6240c12 100644
--- a/test/gleam/pair_test.gleam
+++ b/test/gleam/pair_test.gleam
@@ -56,3 +56,8 @@ pub fn map_second_test() {
pair.map_second(#(-10, 20), dec)
|> should.equal(#(-10, 19))
}
+
+pub fn new_test() {
+ pair.new(1, 2)
+ |> should.equal(#(1, 2))
+}