Skip to content

Commit a177c9f

Browse files
giacomocavalierilpil
authored andcommitted
Add pair.new
1 parent f9539cc commit a177c9f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/gleam/pair.gleam

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,17 @@ pub fn map_second(of pair: #(a, b), with fun: fn(b) -> c) -> #(a, c) {
6969
let #(a, b) = pair
7070
#(a, fun(b))
7171
}
72+
73+
/// Returns a new pair with the given elements. This can also be done using the dedicated
74+
/// syntax instead: `new(1, 2) == #(1, 2)`.
75+
///
76+
/// ## Examples
77+
///
78+
/// ```gleam
79+
/// > new(1, 2)
80+
/// #(1, 2)
81+
/// ```
82+
///
83+
pub fn new(first: a, second: b) -> #(a, b) {
84+
#(first, second)
85+
}

test/gleam/pair_test.gleam

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ pub fn map_second_test() {
5656
pair.map_second(#(-10, 20), dec)
5757
|> should.equal(#(-10, 19))
5858
}
59+
60+
pub fn new_test() {
61+
pair.new(1, 2)
62+
|> should.equal(#(1, 2))
63+
}

0 commit comments

Comments
 (0)