Skip to content

Commit 824fc9a

Browse files
committed
Some JavaScript optimizations
1 parent 529cb7a commit 824fc9a

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

JavaScript/2-functor-proto-fp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function Maybe(x) {
55
}
66

77
Maybe.prototype.map = function(fn) {
8-
return (this.x && fn) ? new Maybe(fn(this.x)) : new Maybe(null);
8+
return new Maybe(this.x && fn ? fn(this.x) : null);
99
};
1010

1111
new Maybe(5).map(x => x * 2).map(console.log);

JavaScript/3-functor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
function maybe(x) {
24
return function(fn) {
35
if (x && fn) {

JavaScript/6-functor-ap-fp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ api.fp.maybe = x => {
1111
map.ap = fnA => fnA(fn => api.fp.mapNull(fn, x));
1212
map.chain = fnM => fnM(x);
1313
return map;
14-
}
14+
};
1515

1616
api.fp.maybe(5)(x => x * 2)(x => ++x)(console.log);
1717
api.fp.maybe(5)(x => x * 2).ap(api.fp.maybe(x => ++x))(console.log);

0 commit comments

Comments
 (0)