Skip to content

Commit bf78e61

Browse files
committed
Make examples self-contained and runnable.
1 parent e864128 commit bf78e61

File tree

2 files changed

+41
-40
lines changed

2 files changed

+41
-40
lines changed

jscomp/test/Import.js

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,10 @@
22

33
var Curry = require("../../lib/js/curry.js");
44

5-
var each = import("../../lib/js/belt_List.js").then(function (m) {
6-
return m.forEach;
7-
});
8-
9-
function eachInt(list, f) {
10-
var arg1 = function (each) {
11-
return Promise.resolve(Curry._2(each, list, f));
12-
};
13-
return each.then(arg1);
14-
}
15-
16-
var beltAsModule = import("../../lib/js/belt_List.js");
17-
185
async function eachIntAsync(list, f) {
19-
var each$1 = await each;
20-
return Curry._2(each$1, list, f);
21-
}
22-
23-
function eachLazy(param) {
24-
return import("../../lib/js/belt_List.js").then(function (m) {
25-
return m.forEach;
26-
});
6+
return Curry._2(await import("../../lib/js/belt_List.js").then(function (m) {
7+
return m.forEach;
8+
}), list, f);
279
}
2810

2911
function eachIntLazy(list, f) {
@@ -36,10 +18,35 @@ function eachIntLazy(list, f) {
3618
return obj.then(arg1);
3719
}
3820

39-
exports.each = each;
40-
exports.eachInt = eachInt;
41-
exports.beltAsModule = beltAsModule;
21+
eachIntLazy({
22+
hd: 1,
23+
tl: {
24+
hd: 2,
25+
tl: {
26+
hd: 3,
27+
tl: /* [] */0
28+
}
29+
}
30+
}, (function (n) {
31+
console.log("lazy", n);
32+
}));
33+
34+
eachIntAsync({
35+
hd: 1,
36+
tl: {
37+
hd: 2,
38+
tl: {
39+
hd: 3,
40+
tl: /* [] */0
41+
}
42+
}
43+
}, (function (n) {
44+
console.log("async", n);
45+
}));
46+
47+
var beltAsModule = import("../../lib/js/belt_List.js");
48+
4249
exports.eachIntAsync = eachIntAsync;
43-
exports.eachLazy = eachLazy;
4450
exports.eachIntLazy = eachIntLazy;
45-
/* No side effect */
51+
exports.beltAsModule = beltAsModule;
52+
/* Not a pure module */

jscomp/test/Import.res

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
let each = Js.import(Belt.List.forEach)
2-
3-
let eachInt = (list: list<int>, f: int => unit) =>
4-
Js.Promise.then_(each => list->each(f)->Js.Promise.resolve, each)
5-
6-
module type BeltList = module type of Belt.List
7-
8-
let beltAsModule = Js.import(module(Belt.List: BeltList))
9-
101
let eachIntAsync = async (list: list<int>, f: int => unit) => {
11-
let each = await each
12-
list->each(f)
2+
list->(await Js.import(Belt.List.forEach))(f)
133
}
144

15-
let eachLazy = () => Js.import(Belt.List.forEach)
16-
175
let eachIntLazy = (list: list<int>, f: int => unit) =>
18-
eachLazy() |> Js.Promise.then_(each => list->each(f)->Js.Promise.resolve)
6+
Js.import(Belt.List.forEach) |> Js.Promise.then_(each => list->each(f)->Js.Promise.resolve)
7+
8+
let _ = list{1, 2, 3}->eachIntLazy(n => Js.log2("lazy", n))
9+
let _ = list{1, 2, 3}->eachIntAsync(n => Js.log2("async", n))
10+
11+
module type BeltList = module type of Belt.List
12+
let beltAsModule = Js.import(module(Belt.List: BeltList))

0 commit comments

Comments
 (0)