// Http.get :: String -> Task Error HTML
const renderPage = curry((destinations, events) => { /* render page */ });
Task.of(renderPage).ap(Http.get('/destinations')).ap(Http.get('/events'));
// Task("<div>some page with dest and events</div>")
Both Http calls will happen instantly and renderPage will be called when both are resolved. Contrast this with the monadic version where one Task must finish before the next fires off. Since we don't need the destinations to retrieve events, we are free from sequential evaluation.
I have been pondering if the following statement was true, and finally wrote a small test to see that it doesn't work this way (the calls are not made instantly, rather, they will be issued one after another. )
if you run this piece of code, you will see that all tasks are chained (the ap method is implemented with chain)
This statement:
I have been pondering if the following statement was true, and finally wrote a small test to see that it doesn't work this way (the calls are not made instantly, rather, they will be issued one after another. )
if you run this piece of code, you will see that all tasks are chained (the
ap
method is implemented withchain
)Am I not following something correctly? It behaves the same way if I wrote it this way:
And it is natural because, this is the implementation of
ap
inTask
: