Skip to content

Instantly share code, notes, and snippets.

@savelichalex
Created September 29, 2016 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save savelichalex/a61d792987eb231e7cce9a8b185ad62b to your computer and use it in GitHub Desktop.
Save savelichalex/a61d792987eb231e7cce9a8b185ad62b to your computer and use it in GitHub Desktop.
(defmacro then->
[promise & forms]
(loop [promise promise,
forms forms]
(if forms
(let [form (first forms)
catch? (= form :catch)
threaded (if (true? catch?)
(with-meta `(.catch ~promise ~(first (next forms))) (meta (first (next forms))))
(with-meta `(.then ~promise ~form) (meta form)))]
(recur threaded (if (true? catch?)
(next (next forms))
(next forms))))
promise)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment