Last active
January 3, 2018 11:54
-
-
Save pietrom/065a5040ef4cf0d3ec7596f011181e17 to your computer and use it in GitHub Desktop.
JS function providing functional 'option' capabilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function option(x) { | |
| return { | |
| map: function(f) { | |
| return x ? option(f(x)) : option() | |
| }, | |
| valueOr: function(d) { | |
| return x || d | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment