Last active
January 3, 2016 13:29
-
-
Save wolfflow/8470050 to your computer and use it in GitHub Desktop.
maybe
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
maybe = (fn) -> -> | |
return if arguments.length is 0 | |
for arg in arguments | |
return if !arg? | |
fn.apply(@, arguments) | |
# Usage | |
Z = maybe((n)->n*n) | |
Z() # undefined | |
Z(16) # 256 |
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
# Shorter one | |
maybe2 = (fn) -> -> | |
return if arguments.length is 0 | |
for arg in arguments | |
return if !arg? | |
fn ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment