Skip to content

Commit 78b9fa6

Browse files
committed
Reactor #0 wrt #1
1 parent 2d134cd commit 78b9fa6

File tree

4 files changed

+50
-37
lines changed

4 files changed

+50
-37
lines changed

index.es6

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
export default {
2-
'return' (value) {
3-
return value;
4-
},
5-
bind (value, f) {
1+
let identity = val => val;
2+
3+
export {identity as return};
4+
5+
let bind = (value, f) => {
66
if (value == null) return null;
77
return f(value);
8-
}
98
}
9+
10+
export {bind as bind};
11+

index.js

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
"use strict";
22

3-
module.exports = {
4-
"return": function _return(value) {
5-
return value;
6-
},
7-
bind: function bind(value, f) {
8-
if (value == null) {
9-
return null;
10-
}return f(value);
11-
}
12-
};
3+
var identity = function (val) {
4+
return val;
5+
};
6+
7+
exports["return"] = identity;
8+
9+
10+
var bind = function (value, f) {
11+
if (value == null) return null;
12+
return f(value);
13+
};
14+
15+
exports.bind = bind;
16+
Object.defineProperty(exports, "__esModule", {
17+
value: true
18+
});

test.es6

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import assert from 'assert';
2-
import mayBe from './';
2+
import {return as returns} from './';
3+
import {bind} from './';
34

45
describe('mayBe Monad test suite', () => {
56
it('should pass the monad law 1', () => {
6-
var fn = (a) => mayBe.return(a * 3);
7-
var lhs = mayBe.bind(mayBe.return(5), fn);
7+
var fn = (a) => returns(a * 3);
8+
var lhs = bind(returns(5), fn);
89
var rhs = fn(5);
910
assert.equal(lhs,rhs);
1011
});
1112

1213
it('should pass the monad law 2', () => {
13-
var m = mayBe.return(5);
14-
var lhs = mayBe.bind(m, mayBe.return);
14+
var m = returns(5);
15+
var lhs = bind(m, returns);
1516
assert.equal(m,lhs);
1617
});
1718

1819
it('should pass the monad law 3', () => {
19-
var f = (a) => mayBe.return(a * 3);
20-
var g = (a) => mayBe.return(a * 5);
21-
var m = mayBe.return(7);
22-
var lhs = mayBe.bind(mayBe.bind(m, f), g);
23-
var rhs = mayBe.bind(m, (x) => mayBe.bind(f(x), g));
20+
var f = (a) => returns(a * 3);
21+
var g = (a) => returns(a * 5);
22+
var m = returns(7);
23+
var lhs = bind(bind(m, f), g);
24+
var rhs = bind(m, (x) => bind(f(x), g));
2425
assert.equal(lhs,rhs);
2526
});
2627
});

test.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,39 @@ var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["defau
44

55
var assert = _interopRequire(require("assert"));
66

7-
var mayBe = _interopRequire(require("./"));
7+
var _ = require("./");
8+
9+
var returns = _["return"];
10+
var bind = _.bind;
11+
812

913
describe("mayBe Monad test suite", function () {
1014
it("should pass the monad law 1", function () {
1115
var fn = function (a) {
12-
return mayBe["return"](a * 3);
16+
return returns(a * 3);
1317
};
14-
var lhs = mayBe.bind(mayBe["return"](5), fn);
18+
var lhs = bind(returns(5), fn);
1519
var rhs = fn(5);
1620
assert.equal(lhs, rhs);
1721
});
1822

1923
it("should pass the monad law 2", function () {
20-
var m = mayBe["return"](5);
21-
var lhs = mayBe.bind(m, mayBe["return"]);
24+
var m = returns(5);
25+
var lhs = bind(m, returns);
2226
assert.equal(m, lhs);
2327
});
2428

2529
it("should pass the monad law 3", function () {
2630
var f = function (a) {
27-
return mayBe["return"](a * 3);
31+
return returns(a * 3);
2832
};
2933
var g = function (a) {
30-
return mayBe["return"](a * 5);
34+
return returns(a * 5);
3135
};
32-
var m = mayBe["return"](7);
33-
var lhs = mayBe.bind(mayBe.bind(m, f), g);
34-
var rhs = mayBe.bind(m, function (x) {
35-
return mayBe.bind(f(x), g);
36+
var m = returns(7);
37+
var lhs = bind(bind(m, f), g);
38+
var rhs = bind(m, function (x) {
39+
return bind(f(x), g);
3640
});
3741
assert.equal(lhs, rhs);
3842
});

0 commit comments

Comments
 (0)