Skip to content

Commit 02d6179

Browse files
committed
Optimize example
1 parent 05c243f commit 02d6179

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

JavaScript/4-functor-fp.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
'use strict';
22

3-
global.api = {};
4-
api.fp = {};
3+
const maybe = x => fn => maybe(x && fn ? fn(x) : null);
54

6-
api.fp.maybe = x => fn => api.fp.maybe(x && fn ? fn(x) : null);
5+
maybe(5)(x => ++x)(console.log);
6+
maybe(5)(x => x * 2)(x => ++x)(console.log);
77

8-
api.fp.maybe(5)(x => ++x)(console.log);
9-
api.fp.maybe(5)(x => x * 2)(x => ++x)(console.log);
10-
11-
api.fp.maybe(5)(null)(console.log);
12-
api.fp.maybe(null)(x => x * 2)(console.log);
8+
maybe(5)(null)(console.log);
9+
maybe(null)(x => x * 2)(console.log);

0 commit comments

Comments
 (0)