Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a31b4eb

Browse files
committedMay 23, 2024
Add missing functions
1 parent 819fb0e commit a31b4eb

14 files changed

+492
-20
lines changed
 

‎src/Core__Option.mjs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,86 @@ function all(options) {
119119
}
120120
}
121121

122+
function all2(param) {
123+
var b = param[1];
124+
var a = param[0];
125+
if (a !== undefined && b !== undefined) {
126+
return [
127+
Caml_option.valFromOption(a),
128+
Caml_option.valFromOption(b)
129+
];
130+
}
131+
132+
}
133+
134+
function all3(param) {
135+
var c = param[2];
136+
var b = param[1];
137+
var a = param[0];
138+
if (a !== undefined && b !== undefined && c !== undefined) {
139+
return [
140+
Caml_option.valFromOption(a),
141+
Caml_option.valFromOption(b),
142+
Caml_option.valFromOption(c)
143+
];
144+
}
145+
146+
}
147+
148+
function all4(param) {
149+
var d = param[3];
150+
var c = param[2];
151+
var b = param[1];
152+
var a = param[0];
153+
if (a !== undefined && b !== undefined && c !== undefined && d !== undefined) {
154+
return [
155+
Caml_option.valFromOption(a),
156+
Caml_option.valFromOption(b),
157+
Caml_option.valFromOption(c),
158+
Caml_option.valFromOption(d)
159+
];
160+
}
161+
162+
}
163+
164+
function all5(param) {
165+
var e = param[4];
166+
var d = param[3];
167+
var c = param[2];
168+
var b = param[1];
169+
var a = param[0];
170+
if (a !== undefined && b !== undefined && c !== undefined && d !== undefined && e !== undefined) {
171+
return [
172+
Caml_option.valFromOption(a),
173+
Caml_option.valFromOption(b),
174+
Caml_option.valFromOption(c),
175+
Caml_option.valFromOption(d),
176+
Caml_option.valFromOption(e)
177+
];
178+
}
179+
180+
}
181+
182+
function all6(param) {
183+
var f = param[5];
184+
var e = param[4];
185+
var d = param[3];
186+
var c = param[2];
187+
var b = param[1];
188+
var a = param[0];
189+
if (a !== undefined && b !== undefined && c !== undefined && d !== undefined && e !== undefined && f !== undefined) {
190+
return [
191+
Caml_option.valFromOption(a),
192+
Caml_option.valFromOption(b),
193+
Caml_option.valFromOption(c),
194+
Caml_option.valFromOption(d),
195+
Caml_option.valFromOption(e),
196+
Caml_option.valFromOption(f)
197+
];
198+
}
199+
200+
}
201+
122202
var mapWithDefault = mapOr;
123203

124204
var getWithDefault = getOr;
@@ -139,5 +219,10 @@ export {
139219
equal ,
140220
compare ,
141221
all ,
222+
all2 ,
223+
all3 ,
224+
all4 ,
225+
all5 ,
226+
all6 ,
142227
}
143228
/* No side effect */

‎src/Core__Option.res

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,38 @@ let all = options => {
116116
| None => Some(acc)
117117
}
118118
}
119+
120+
let all2 = ((a, b)) => {
121+
switch (a, b) {
122+
| (Some(a), Some(b)) => Some((a, b))
123+
| _ => None
124+
}
125+
}
126+
127+
let all3 = ((a, b, c)) => {
128+
switch (a, b, c) {
129+
| (Some(a), Some(b), Some(c)) => Some((a, b, c))
130+
| _ => None
131+
}
132+
}
133+
134+
let all4 = ((a, b, c, d)) => {
135+
switch (a, b, c, d) {
136+
| (Some(a), Some(b), Some(c), Some(d)) => Some((a, b, c, d))
137+
| _ => None
138+
}
139+
}
140+
141+
let all5 = ((a, b, c, d, e)) => {
142+
switch (a, b, c, d, e) {
143+
| (Some(a), Some(b), Some(c), Some(d), Some(e)) => Some((a, b, c, d, e))
144+
| _ => None
145+
}
146+
}
147+
148+
let all6 = ((a, b, c, d, e, f)) => {
149+
switch (a, b, c, d, e, f) {
150+
| (Some(a), Some(b), Some(c), Some(d), Some(e), Some(f)) => Some((a, b, c, d, e, f))
151+
| _ => None
152+
}
153+
}

‎src/Core__Option.resi

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,41 @@ Option.all([Some(1), None]) // None
264264
```
265265
*/
266266
let all: array<option<'a>> => option<array<'a>>
267+
268+
/**
269+
`all2((o1, o2))`. Like `all()`, but with a fixed size tuple of 2
270+
*/
271+
let all2: ((option<'a>, option<'b>)) => option<('a, 'b)>
272+
273+
/**
274+
`all3((o1, o2, o3))`. Like `all()`, but with a fixed size tuple of 2
275+
*/
276+
let all3: ((option<'a>, option<'b>, option<'c>)) => option<('a, 'b, 'c)>
277+
278+
/**
279+
`all4((o1, o2, o3, o4))`. Like `all()`, but with a fixed size tuple of 2
280+
*/
281+
let all4: ((option<'a>, option<'b>, option<'c>, option<'d>)) => option<('a, 'b, 'c, 'd)>
282+
283+
/**
284+
`all5((o1, o2, o3, o4, o5))`. Like `all()`, but with a fixed size tuple of 2
285+
*/
286+
let all5: ((option<'a>, option<'b>, option<'c>, option<'d>, option<'e>)) => option<(
287+
'a,
288+
'b,
289+
'c,
290+
'd,
291+
'e,
292+
)>
293+
294+
/**
295+
`all6((o1, o2, o3, o4, o5, o6))`. Like `all()`, but with a fixed size tuple of 2
296+
*/
297+
let all6: ((option<'a>, option<'b>, option<'c>, option<'d>, option<'e>, option<'f>)) => option<(
298+
'a,
299+
'b,
300+
'c,
301+
'd,
302+
'e,
303+
'f,
304+
)>

‎src/Core__Result.mjs

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,226 @@ function all(results) {
132132
}
133133
}
134134

135+
function all2(param) {
136+
var b = param[1];
137+
var a = param[0];
138+
if (a.TAG === "Ok") {
139+
if (b.TAG === "Ok") {
140+
return {
141+
TAG: "Ok",
142+
_0: [
143+
a._0,
144+
b._0
145+
]
146+
};
147+
} else {
148+
return {
149+
TAG: "Error",
150+
_0: b._0
151+
};
152+
}
153+
} else {
154+
return {
155+
TAG: "Error",
156+
_0: a._0
157+
};
158+
}
159+
}
160+
161+
function all3(param) {
162+
var c = param[2];
163+
var b = param[1];
164+
var a = param[0];
165+
if (a.TAG === "Ok") {
166+
if (b.TAG === "Ok") {
167+
if (c.TAG === "Ok") {
168+
return {
169+
TAG: "Ok",
170+
_0: [
171+
a._0,
172+
b._0,
173+
c._0
174+
]
175+
};
176+
} else {
177+
return {
178+
TAG: "Error",
179+
_0: c._0
180+
};
181+
}
182+
} else {
183+
return {
184+
TAG: "Error",
185+
_0: b._0
186+
};
187+
}
188+
} else {
189+
return {
190+
TAG: "Error",
191+
_0: a._0
192+
};
193+
}
194+
}
195+
196+
function all4(param) {
197+
var d = param[3];
198+
var c = param[2];
199+
var b = param[1];
200+
var a = param[0];
201+
if (a.TAG === "Ok") {
202+
if (b.TAG === "Ok") {
203+
if (c.TAG === "Ok") {
204+
if (d.TAG === "Ok") {
205+
return {
206+
TAG: "Ok",
207+
_0: [
208+
a._0,
209+
b._0,
210+
c._0,
211+
d._0
212+
]
213+
};
214+
} else {
215+
return {
216+
TAG: "Error",
217+
_0: d._0
218+
};
219+
}
220+
} else {
221+
return {
222+
TAG: "Error",
223+
_0: c._0
224+
};
225+
}
226+
} else {
227+
return {
228+
TAG: "Error",
229+
_0: b._0
230+
};
231+
}
232+
} else {
233+
return {
234+
TAG: "Error",
235+
_0: a._0
236+
};
237+
}
238+
}
239+
240+
function all5(param) {
241+
var e = param[4];
242+
var d = param[3];
243+
var c = param[2];
244+
var b = param[1];
245+
var a = param[0];
246+
if (a.TAG === "Ok") {
247+
if (b.TAG === "Ok") {
248+
if (c.TAG === "Ok") {
249+
if (d.TAG === "Ok") {
250+
if (e.TAG === "Ok") {
251+
return {
252+
TAG: "Ok",
253+
_0: [
254+
a._0,
255+
b._0,
256+
c._0,
257+
d._0,
258+
e._0
259+
]
260+
};
261+
} else {
262+
return {
263+
TAG: "Error",
264+
_0: e._0
265+
};
266+
}
267+
} else {
268+
return {
269+
TAG: "Error",
270+
_0: d._0
271+
};
272+
}
273+
} else {
274+
return {
275+
TAG: "Error",
276+
_0: c._0
277+
};
278+
}
279+
} else {
280+
return {
281+
TAG: "Error",
282+
_0: b._0
283+
};
284+
}
285+
} else {
286+
return {
287+
TAG: "Error",
288+
_0: a._0
289+
};
290+
}
291+
}
292+
293+
function all6(param) {
294+
var f = param[5];
295+
var e = param[4];
296+
var d = param[3];
297+
var c = param[2];
298+
var b = param[1];
299+
var a = param[0];
300+
if (a.TAG === "Ok") {
301+
if (b.TAG === "Ok") {
302+
if (c.TAG === "Ok") {
303+
if (d.TAG === "Ok") {
304+
if (e.TAG === "Ok") {
305+
if (f.TAG === "Ok") {
306+
return {
307+
TAG: "Ok",
308+
_0: [
309+
a._0,
310+
b._0,
311+
c._0,
312+
d._0,
313+
e._0,
314+
f._0
315+
]
316+
};
317+
} else {
318+
return {
319+
TAG: "Error",
320+
_0: f._0
321+
};
322+
}
323+
} else {
324+
return {
325+
TAG: "Error",
326+
_0: e._0
327+
};
328+
}
329+
} else {
330+
return {
331+
TAG: "Error",
332+
_0: d._0
333+
};
334+
}
335+
} else {
336+
return {
337+
TAG: "Error",
338+
_0: c._0
339+
};
340+
}
341+
} else {
342+
return {
343+
TAG: "Error",
344+
_0: b._0
345+
};
346+
}
347+
} else {
348+
return {
349+
TAG: "Error",
350+
_0: a._0
351+
};
352+
}
353+
}
354+
135355
var mapWithDefault = mapOr;
136356

137357
var getWithDefault = getOr;
@@ -151,5 +371,10 @@ export {
151371
forEach ,
152372
mapError ,
153373
all ,
374+
all2 ,
375+
all3 ,
376+
all4 ,
377+
all5 ,
378+
all6 ,
154379
}
155380
/* No side effect */

‎src/Core__Result.res

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,53 @@ let all = results => {
113113
| None => Ok(acc)
114114
}
115115
}
116+
117+
let all2 = ((a, b)) => {
118+
switch (a, b) {
119+
| (Ok(a), Ok(b)) => Ok((a, b))
120+
| (Error(a), _) => Error(a)
121+
| (_, Error(b)) => Error(b)
122+
}
123+
}
124+
125+
let all3 = ((a, b, c)) => {
126+
switch (a, b, c) {
127+
| (Ok(a), Ok(b), Ok(c)) => Ok((a, b, c))
128+
| (Error(a), _, _) => Error(a)
129+
| (_, Error(b), _) => Error(b)
130+
| (_, _, Error(c)) => Error(c)
131+
}
132+
}
133+
134+
let all4 = ((a, b, c, d)) => {
135+
switch (a, b, c, d) {
136+
| (Ok(a), Ok(b), Ok(c), Ok(d)) => Ok((a, b, c, d))
137+
| (Error(a), _, _, _) => Error(a)
138+
| (_, Error(b), _, _) => Error(b)
139+
| (_, _, Error(c), _) => Error(c)
140+
| (_, _, _, Error(d)) => Error(d)
141+
}
142+
}
143+
144+
let all5 = ((a, b, c, d, e)) => {
145+
switch (a, b, c, d, e) {
146+
| (Ok(a), Ok(b), Ok(c), Ok(d), Ok(e)) => Ok((a, b, c, d, e))
147+
| (Error(a), _, _, _, _) => Error(a)
148+
| (_, Error(b), _, _, _) => Error(b)
149+
| (_, _, Error(c), _, _) => Error(c)
150+
| (_, _, _, Error(d), _) => Error(d)
151+
| (_, _, _, _, Error(e)) => Error(e)
152+
}
153+
}
154+
155+
let all6 = ((a, b, c, d, e, f)) => {
156+
switch (a, b, c, d, e, f) {
157+
| (Ok(a), Ok(b), Ok(c), Ok(d), Ok(e), Ok(f)) => Ok((a, b, c, d, e, f))
158+
| (Error(a), _, _, _, _, _) => Error(a)
159+
| (_, Error(b), _, _, _, _) => Error(b)
160+
| (_, _, Error(c), _, _, _) => Error(c)
161+
| (_, _, _, Error(d), _, _) => Error(d)
162+
| (_, _, _, _, Error(e), _) => Error(e)
163+
| (_, _, _, _, _, Error(f)) => Error(f)
164+
}
165+
}

‎src/Core__Result.resi

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,42 @@ Result.all([Ok(1), Error(1)]) // Error(1)
246246
```
247247
*/
248248
let all: array<result<'a, 'b>> => result<array<'a>, 'b>
249+
250+
/**
251+
`all2((r1, r2))`. Like `all()`, but with a fixed size tuple of 2
252+
*/
253+
let all2: ((result<'r1, 'e>, result<'r2, 'e>)) => result<('r1, 'r2), 'e>
254+
255+
/**
256+
`all3((r1, r2, r3))`. Like `all()`, but with a fixed size tuple of 2
257+
*/
258+
let all3: ((result<'r1, 'e>, result<'r2, 'e>, result<'r3, 'e>)) => result<('r1, 'r2, 'r3), 'e>
259+
260+
/**
261+
`all4((r1, r2, r3, r4))`. Like `all()`, but with a fixed size tuple of 2
262+
*/
263+
let all4: ((result<'r1, 'e>, result<'r2, 'e>, result<'r3, 'e>, result<'r4, 'e>)) => result<
264+
('r1, 'r2, 'r3, 'r4),
265+
'e,
266+
>
267+
268+
/**
269+
`all5((r1, r2, r3, r4, r5))`. Like `all()`, but with a fixed size tuple of 2
270+
*/
271+
let all5: (
272+
(result<'r1, 'e>, result<'r2, 'e>, result<'r3, 'e>, result<'r4, 'e>, result<'r5, 'e>)
273+
) => result<('r1, 'r2, 'r3, 'r4, 'r5), 'e>
274+
275+
/**
276+
`all6((r1, r2, r3, r4, r5, r6))`. Like `all()`, but with a fixed size tuple of 2
277+
*/
278+
let all6: (
279+
(
280+
result<'r1, 'e>,
281+
result<'r2, 'e>,
282+
result<'r3, 'e>,
283+
result<'r4, 'e>,
284+
result<'r5, 'e>,
285+
result<'r6, 'e>,
286+
)
287+
) => result<('r1, 'r2, 'r3, 'r4, 'r5, 'r6), 'e>

‎test/intl/Intl__CollatorTest.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ console.log("---");
55

66
console.log("Intl.Collator");
77

8-
new Intl.Collator(undefined, undefined);
8+
new Intl.Collator();
99

10-
new Intl.Collator(["en-US"], undefined);
10+
new Intl.Collator(["en-US"]);
1111

1212
var _collator = new Intl.Collator([
1313
"en-US",
1414
"en-GB"
15-
], undefined);
15+
]);
1616

1717
var collator = new Intl.Collator(["en-US"], {
1818
sensitivity: "base",
@@ -24,7 +24,7 @@ var collator = new Intl.Collator(["en-US"], {
2424
Intl.Collator.supportedLocalesOf([
2525
"en-US",
2626
"en-GB"
27-
], undefined);
27+
]);
2828

2929
Intl.Collator.supportedLocalesOf([
3030
"en-US",
@@ -37,7 +37,7 @@ console.log(collator.resolvedOptions());
3737

3838
console.log(collator.compare("hi", "hï"));
3939

40-
console.log(Intl.Collator.supportedLocalesOf(["hi"], undefined));
40+
console.log(Intl.Collator.supportedLocalesOf(["hi"]));
4141

4242
export {
4343
_collator ,

‎test/intl/Intl__DateTimeFormatTest.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ console.log("Intl.DateTimeFormat");
99
Intl.DateTimeFormat.supportedLocalesOf([
1010
"en-US",
1111
"en-GB"
12-
], undefined);
12+
]);
1313

1414
Intl.DateTimeFormat.supportedLocalesOf([
1515
"en-US",
@@ -77,7 +77,7 @@ var formatter$6 = new Intl.DateTimeFormat(undefined, (newrecord$4.timeZoneName =
7777

7878
console.log(formatter$6.format(new Date(Date.now())));
7979

80-
var resolvedOptions = new Intl.DateTimeFormat(undefined, undefined).resolvedOptions();
80+
var resolvedOptions = new Intl.DateTimeFormat().resolvedOptions();
8181

8282
var timeZone = resolvedOptions.timeZone;
8383

‎test/intl/Intl__ListFormatTest.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ console.log("---");
55

66
console.log("Intl.ListFormat");
77

8-
new Intl.ListFormat(undefined, undefined);
8+
new Intl.ListFormat();
99

1010
new Intl.ListFormat([
1111
"en-US",
1212
"en-GB"
13-
], undefined);
13+
]);
1414

1515
var _formatter = new Intl.ListFormat([
1616
"en-US",
@@ -23,7 +23,7 @@ var _formatter = new Intl.ListFormat([
2323
Intl.ListFormat.supportedLocalesOf([
2424
"en-US",
2525
"en-GB"
26-
], undefined);
26+
]);
2727

2828
Intl.ListFormat.supportedLocalesOf([
2929
"en-US",

‎test/intl/Intl__LocaleTest.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ console.log("---");
55

66
console.log("Intl.Locale");
77

8-
var _locale = new Intl.Locale("en-US", undefined);
8+
var _locale = new Intl.Locale("en-US");
99

1010
var locale = new Intl.Locale("en-US", {
1111
calendar: "hebrew",

‎test/intl/Intl__NumberFormatTest.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var currencyFormatter = new Intl.NumberFormat(["fr-FR"], {
1515
console.log(Intl.NumberFormat.supportedLocalesOf([
1616
"fr-FR",
1717
"en-US"
18-
], undefined));
18+
]));
1919

2020
console.log(currencyFormatter.format(123.23));
2121

‎test/intl/Intl__PluralRulesTest.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ console.log("---");
55

66
console.log("Intl.PluralRules");
77

8-
new Intl.PluralRules(undefined, undefined);
8+
new Intl.PluralRules();
99

1010
new Intl.PluralRules([
1111
"en-US",
1212
"en-GB"
13-
], undefined);
13+
]);
1414

1515
var _formatter = new Intl.PluralRules(undefined, {
1616
type: "ordinal",

‎test/intl/Intl__RelativeTimeFormatTest.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ console.log("Intl.RelativeTimeFormat");
88
Intl.RelativeTimeFormat.supportedLocalesOf([
99
"en-US",
1010
"en-GB"
11-
], undefined);
11+
]);
1212

1313
Intl.RelativeTimeFormat.supportedLocalesOf([
1414
"en-US",
@@ -17,12 +17,12 @@ Intl.RelativeTimeFormat.supportedLocalesOf([
1717
localeMatcher: "lookup"
1818
});
1919

20-
new Intl.RelativeTimeFormat(undefined, undefined);
20+
new Intl.RelativeTimeFormat();
2121

2222
new Intl.RelativeTimeFormat([
2323
"en-US",
2424
"en-GB"
25-
], undefined);
25+
]);
2626

2727
var _formatter = new Intl.RelativeTimeFormat(undefined, {
2828
numeric: "always",

‎test/intl/Intl__SegmenterTest.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ console.log("Intl.Segmenter");
88
Intl.Segmenter.supportedLocalesOf([
99
"en-US",
1010
"en-GB"
11-
], undefined);
11+
]);
1212

1313
Intl.Segmenter.supportedLocalesOf([
1414
"en-US",
@@ -17,12 +17,12 @@ Intl.Segmenter.supportedLocalesOf([
1717
localeMatcher: "lookup"
1818
});
1919

20-
new Intl.Segmenter(undefined, undefined);
20+
new Intl.Segmenter();
2121

2222
new Intl.Segmenter([
2323
"en-US",
2424
"en-GB"
25-
], undefined);
25+
]);
2626

2727
var _formatter = new Intl.Segmenter(undefined, {
2828
granularity: "word"

0 commit comments

Comments
 (0)
Please sign in to comment.