Created
October 30, 2015 11:21
-
-
Save toburger/93f4a412ff7f01282b41 to your computer and use it in GitHub Desktop.
This file contains 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 maybe(value) { | |
const isEmpty = () => value === undefined || value === null; | |
const nonEmpty = () => !isEmpty(); | |
return { | |
map(f) { return isEmpty() ? this : maybe(f(value)) }, | |
getOrElse(n) { return isEmpty() ? n : value }, | |
isEmpty: isEmpty, | |
nonEmpty: nonEmpty | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage: