We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 05c243f commit 02d6179Copy full SHA for 02d6179
JavaScript/4-functor-fp.js
@@ -1,12 +1,9 @@
1
'use strict';
2
3
-global.api = {};
4
-api.fp = {};
+const maybe = x => fn => maybe(x && fn ? fn(x) : null);
5
6
-api.fp.maybe = x => fn => api.fp.maybe(x && fn ? fn(x) : null);
+maybe(5)(x => ++x)(console.log);
+maybe(5)(x => x * 2)(x => ++x)(console.log);
7
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);
+maybe(5)(null)(console.log);
+maybe(null)(x => x * 2)(console.log);
0 commit comments