Skip to content

Instantly share code, notes, and snippets.

@wolfflow
Last active January 3, 2016 13:29
Show Gist options
  • Save wolfflow/8470050 to your computer and use it in GitHub Desktop.
Save wolfflow/8470050 to your computer and use it in GitHub Desktop.
maybe
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
# 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