Skip to content

Commit 27af64b

Browse files
authored
Merge pull request #11 from cstuncsik/master
Fixing #10
2 parents 50e5b58 + eb34ab0 commit 27af64b

File tree

3 files changed

+27
-33
lines changed

3 files changed

+27
-33
lines changed

src/ch06/tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ QUnit.test('showStudent: cleanInput', function (assert) {
4444

4545
const input = ['', '-44-44-', '44444', ' 4 ', ' 4-4 '];
4646
const assertions = ['', '4444', '44444', '4', '44'];
47-
expect(input.length);
47+
assert.expect(input.length);
4848
input.forEach(function (val, key) {
4949
assert.equal(cleanInput(val), assertions[key]);
5050
});

src/ch08/tests.js

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@ QUnit.test("Generator 2", function (assert) {
6565
assert.equal(r.next().value, 2);
6666
});
6767

68+
QUnit.test("Generator 3", function (assert) {
69+
function range(start, end) {
70+
return {
71+
[Symbol.iterator]() {
72+
return this;
73+
},
74+
75+
next() {
76+
if(start < end) {
77+
return { value: start++, done:false };
78+
}
79+
return { done: true, value:end };
80+
}
81+
};
82+
}
83+
84+
let res = [];
85+
for(let num of range(0,5)) {
86+
console.log(num);
87+
res.push(num);
88+
}
89+
assert.deepEqual(res, [0,1,2,3,4]);
90+
});
6891

6992
QUnit.test("Fetching student data with async calls", function (assert) {
7093

@@ -89,35 +112,9 @@ QUnit.test("Fetching student data with async calls", function (assert) {
89112
.catch(function (error) {
90113
console.log('Error occurred: ' + error.message);
91114
});
92-
expect(0); // when run this code prints to the screen all of the output through the IO monad, so nothing to expect
115+
assert.expect(0); // when run this code prints to the screen all of the output through the IO monad, so nothing to expect
93116
});
94117

95-
96-
QUnit.test("Fetching student data with async calls", function (assert) {
97-
function range(start, end) {
98-
return {
99-
[Symbol.iterator]() {
100-
return this;
101-
},
102-
103-
next() {
104-
if(start < end) {
105-
return { value: start++, done:false };
106-
}
107-
return { done: true, value:end };
108-
}
109-
};
110-
}
111-
112-
let res = [];
113-
for(let num of range(0,5)) {
114-
console.log(num);
115-
res.push(num);
116-
}
117-
assert.deepEqual(res, [0,1,2,3,4]);
118-
});
119-
120-
121118
QUnit.test("Rx test", function (assert) {
122119

123120
let res = [];

src/model/monad/IO.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ exports.IO = class IO {
2121
return new exports.IO(fn);
2222
}
2323

24-
map(fn) {
25-
var self = this;
26-
return new exports.IO(function () {
27-
return fn(self.effect());
28-
});
24+
map(fn) {
25+
return new IO(() => fn(this.effect()));
2926
}
3027

3128
chain(fn) {

0 commit comments

Comments
 (0)