Skip to content

Instantly share code, notes, and snippets.

@kurisuwhyte
Created August 31, 2013 17:01
Show Gist options
  • Save kurisuwhyte/6399459 to your computer and use it in GitHub Desktop.
Save kurisuwhyte/6399459 to your computer and use it in GitHub Desktop.
// As long as the functions work on Promise values, you don't need to use `.then/.chain`.
// In fact, I'd say that using `.then` directly is usually an anti-pattern, as you can easily liftN(fn)
var tweets = getTweetsFor("swannodette")
var firstUrl = expandUrl(first(parseUrls(tweets)))
var response = httpGet(firstUrl)
response.then(function(data) { console.log("Most recent link text: ", data) }
,function(error) { console.log("Error with the twitterverse: ", error) })
/* The CLJS
;; would be easy to achieve with do-syntax macros for monads in JS, with sweet.js or something
;; But still fairly nice eh. I wonder how the try/catch construct is compiled by the `go` macro.
(go (try
(let [tweets (<? (get-tweets-for "swannodette"))
first-url (<? (expand-url (first (parse-urls tweets))))
response (<? (http-get first-url))]
(. js/console (log "Most recent link text:" response)))
(catch js/Error e
(. js/console (error "Error with the twitterverse:" e)))))
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment