Skip to content

Instantly share code, notes, and snippets.

@groundwater
Created February 7, 2013 04:11
Show Gist options
  • Save groundwater/4728428 to your computer and use it in GitHub Desktop.
Save groundwater/4728428 to your computer and use it in GitHub Desktop.
# Do comprehension chains Monads together
var x = do
a <- maybe_null( 'Hello World' ) # If returns null/None, none of the following is executed
b <- async_call_1( a ) # Returns a Promise
c <- async_call_2( b ) # Only executed once the preceding promise is fulfilled
d <- async_call_3( c )
return d
x.get(function(err,ok){
# function called with err if the above comprehension failed
# called with ok=d if the above comprehension succeeded
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment