Skip to content

Commit c6142a3

Browse files
committed
Add Stdlib.Pair
1 parent e51c61a commit c6142a3

File tree

8 files changed

+55
-2
lines changed

8 files changed

+55
-2
lines changed

lib/es6/Stdlib.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID: "Assert_failure",
1313
_1: [
1414
"Stdlib.res",
15-
118,
15+
119,
1616
4
1717
],
1818
Error: new Error()
@@ -63,6 +63,8 @@ let Option;
6363

6464
let Ordering;
6565

66+
let Pair;
67+
6668
let $$Promise;
6769

6870
let $$RegExp;
@@ -138,6 +140,7 @@ export {
138140
$$Object,
139141
Option,
140142
Ordering,
143+
Pair,
141144
$$Promise,
142145
$$RegExp,
143146
Result,

lib/es6/Stdlib_Pair.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

lib/js/Stdlib.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID: "Assert_failure",
1313
_1: [
1414
"Stdlib.res",
15-
118,
15+
119,
1616
4
1717
],
1818
Error: new Error()
@@ -63,6 +63,8 @@ let Option;
6363

6464
let Ordering;
6565

66+
let Pair;
67+
6668
let $$Promise;
6769

6870
let $$RegExp;
@@ -137,6 +139,7 @@ exports.Nullable = Nullable;
137139
exports.$$Object = $$Object;
138140
exports.Option = Option;
139141
exports.Ordering = Ordering;
142+
exports.Pair = Pair;
140143
exports.$$Promise = $$Promise;
141144
exports.$$RegExp = $$RegExp;
142145
exports.Result = Result;

lib/js/Stdlib_Pair.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

packages/artifacts.txt

+6
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ lib/es6/Stdlib_Nullable.js
186186
lib/es6/Stdlib_Object.js
187187
lib/es6/Stdlib_Option.js
188188
lib/es6/Stdlib_Ordering.js
189+
lib/es6/Stdlib_Pair.js
189190
lib/es6/Stdlib_Promise.js
190191
lib/es6/Stdlib_RegExp.js
191192
lib/es6/Stdlib_Result.js
@@ -358,6 +359,7 @@ lib/js/Stdlib_Nullable.js
358359
lib/js/Stdlib_Object.js
359360
lib/js/Stdlib_Option.js
360361
lib/js/Stdlib_Ordering.js
362+
lib/js/Stdlib_Pair.js
361363
lib/js/Stdlib_Promise.js
362364
lib/js/Stdlib_RegExp.js
363365
lib/js/Stdlib_Result.js
@@ -1151,6 +1153,10 @@ lib/ocaml/Stdlib_Ordering.cmi
11511153
lib/ocaml/Stdlib_Ordering.cmj
11521154
lib/ocaml/Stdlib_Ordering.cmt
11531155
lib/ocaml/Stdlib_Ordering.res
1156+
lib/ocaml/Stdlib_Pair.cmi
1157+
lib/ocaml/Stdlib_Pair.cmj
1158+
lib/ocaml/Stdlib_Pair.cmt
1159+
lib/ocaml/Stdlib_Pair.res
11541160
lib/ocaml/Stdlib_Promise.cmi
11551161
lib/ocaml/Stdlib_Promise.cmj
11561162
lib/ocaml/Stdlib_Promise.cmt

runtime/Pervasives.res

+3
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ external ignore: 'a => unit = "%ignore"
283283

284284
/* Pair operations */
285285

286+
@deprecated("Use `Pair.first` instead. This will be removed in v13")
286287
external fst: (('a, 'b)) => 'a = "%field0"
288+
289+
@deprecated("Use `Pair.second` instead. This will be removed in v13")
287290
external snd: (('a, 'b)) => 'b = "%field1"
288291

289292
/* References */

runtime/Stdlib.res

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Nullable = Stdlib_Nullable
2020
module Object = Stdlib_Object
2121
module Option = Stdlib_Option
2222
module Ordering = Stdlib_Ordering
23+
module Pair = Stdlib_Pair
2324
module Promise = Stdlib_Promise
2425
module RegExp = Stdlib_RegExp
2526
module Result = Stdlib_Result

runtime/Stdlib_Pair.res

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/***
2+
This module provides functions to work with pairs, which are 2-element tuples.
3+
*/
4+
5+
type t<'a, 'b> = ('a, 'b)
6+
7+
/**
8+
`first(pair)` returns the first element of a pair.
9+
10+
## Examples
11+
12+
```rescript
13+
Pair.first((1, 2))->assertEqual(1)
14+
```
15+
*/
16+
external first: (('a, 'b)) => 'a = "%field0"
17+
18+
/**
19+
`second(pair)` returns the second element of a pair.
20+
21+
## Examples
22+
23+
```rescript
24+
Pair.second((1, 2))->assertEqual(2)
25+
```
26+
*/
27+
external second: (('a, 'b)) => 'b = "%field1"
28+
29+
/**
30+
`ignore(option)` ignores the provided pair and returns unit.
31+
32+
This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
33+
without having to store or process it further.
34+
*/
35+
external ignore: ('a, 'b) => unit = "%ignore"

0 commit comments

Comments
 (0)