Skip to content

Commit 719f2d7

Browse files
committed
Change usage example and comments
1 parent 98c2c46 commit 719f2d7

File tree

7 files changed

+23
-6
lines changed

7 files changed

+23
-6
lines changed

JavaScript/1-functor-proto.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ Maybe.prototype.map = function(fn) {
1212
}
1313
};
1414

15+
// Usage
16+
17+
new Maybe(5).map().map(console.log);
1518
new Maybe(5).map(x => x * 2).map(console.log);
1619
new Maybe(null).map(x => x * 2).map(console.log);

JavaScript/2-functor-proto-fp.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ Maybe.prototype.map = function(fn) {
88
return new Maybe(this.x && fn ? fn(this.x) : null);
99
};
1010

11+
// Usage
12+
13+
new Maybe(5).map().map(console.log);
1114
new Maybe(5).map(x => x * 2).map(console.log);
1215
new Maybe(null).map(x => x * 2).map(console.log);

JavaScript/3-functor.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ function maybe(x) {
1010
};
1111
}
1212

13+
// Usage
14+
15+
maybe(5)()(console.log);
16+
maybe(5)(x => ++x)(console.log);
1317
maybe(5)(x => x * 2)(console.log);
1418
maybe(null)(x => x * 2)(console.log);
19+
maybe(5)(x => x * 2)(x => ++x)(console.log);

JavaScript/4-functor-fp.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
const maybe = x => fn => maybe(x && fn ? fn(x) : null);
44

5-
maybe(5)(x => ++x)(console.log);
6-
maybe(5)(x => x * 2)(x => ++x)(console.log);
5+
// Usage
76

8-
maybe(5)(null)(console.log);
7+
maybe(5)()(console.log);
8+
maybe(5)(x => ++x)(console.log);
9+
maybe(5)(x => x * 2)(console.log);
910
maybe(null)(x => x * 2)(console.log);
11+
maybe(5)(x => x * 2)(x => ++x)(console.log);

JavaScript/5-functor-ap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Maybe.prototype.ap = function(maybe) {
1414
))));
1515
};
1616

17+
// Usage
18+
1719
const a = new Maybe(5);
1820
const f1 = new Maybe(x => x * 2);
1921
const f2 = new Maybe(x => ++x);

JavaScript/6-functor-ap-fp.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ fp.maybe = x => {
1111
return map;
1212
};
1313

14+
// Usage
15+
1416
fp.maybe(5)(x => x * 2)(x => ++x)(console.log);
1517
fp.maybe(5)(x => x * 2).ap(fp.maybe(x => ++x))(console.log);
1618
fp.maybe(5).chain(x => fp.maybe(x * 2))(x => ++x)(console.log);

JavaScript/7-functor-path.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fp.path = data => (
1515

1616
fp.maybe = x => fn => fp.maybe(x && fn ? fn(x) : null);
1717

18-
// Usage example:
18+
// Usage
1919

2020
const fs = require('fs');
2121

@@ -33,7 +33,7 @@ const config = {
3333
}
3434
};
3535

36-
// Imperative style:
36+
// Imperative style
3737

3838
if (
3939
config &&
@@ -50,7 +50,7 @@ if (
5050
});
5151
}
5252

53-
// Functional style:
53+
// Functional style
5454

5555
fp.path(config)('server.ssl.key.filename')(
5656
file => fs.readFile(file, (err, data) => {

0 commit comments

Comments
 (0)