aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2023-05-31 23:21:06 +0200
committerLouis Pilfold <louis@lpil.uk>2023-06-01 18:10:44 +0100
commita177c9f9a61cca39e63b8b809d1b866004bfce2a (patch)
tree404f50d368d2e4cbb340870f8ae2572c62706d2c
parentf9539cc343249be45915c9f5b8778fbcdd6c0750 (diff)
downloadgleam_stdlib-a177c9f9a61cca39e63b8b809d1b866004bfce2a.tar.gz
gleam_stdlib-a177c9f9a61cca39e63b8b809d1b866004bfce2a.zip
Add `pair.new`
-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))
+}