Skip to content

Instantly share code, notes, and snippets.

View nat-n's full-sized avatar
🏠
Working from home

Nat Noordanus nat-n

🏠
Working from home
View GitHub Profile
@nat-n
nat-n / Monadik_Async_Chain.coffee
Created September 3, 2012 14:48
In the smallest possible Coffeescript code, chain an array of async callbacks to "thread" their evaluation order. Inspired from Haskell
# Construct a chained array of callbacks that "thread" a sequence of async functions in the smallest possible code.
# tldr; call the next async function in fn, "wait" for its callback to store the result and call the next async callback in cb
# each async function
# accepts 1 callback argument
# passes 1 arg of result data to the callback
# construct the callback
# when callback in cb evaluates, replaces itself in cb array with the result
# calls the next callback in cb
# after last callback in cb, return joined results stored in cb