Skip to content

Commit 6b682ec

Browse files
committed
JavaScript minimalistic solution
1 parent c36cf20 commit 6b682ec

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

JavaScript/maybe5.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
function maybe(x) {
4+
return fn => maybe((x && fn) ? fn(x) : null);
5+
}
6+
7+
maybe(5)(x => ++x)(console.log);
8+
maybe(5)(x => x * 2)(x => ++x)(console.log);
9+
10+
maybe(5)(null)(console.log);
11+
maybe(null)(x => x * 2)(console.log);

0 commit comments

Comments
 (0)