I am wanting to convert a list of id's into a list of Tasks
, and run them concurrently, similar to Promise.all
. I am aware of applicatives, but I want to apply an unknown number of tasks so I don't believe that will be the best approach.
Say I have a Task
that contains an array of Task
's.
Task.of([Task.of(1), Task.of(2)])
Is there anyway to fold the tasks down into a single task that will run them all, or is there a better way that I can handle the data transformation.
The snippet has data.Task
included that you can copy if you want to provide an example.
http://folktalegithubio.readthedocs.io/en/latest/api/data/task/
// Task([Task])
Task.of([0, 1, 2])
.map(t => t.map(Task.of))
.fork(console.error, console.log)
<script src="https://codepen.io/synthet1c/pen/bWOZEM.js"></script>
control.async.parallel
is exactly what you are looking for.
I am aware of applicatives, but I want to apply an unknown number of tasks so I don't believe that will be the best approach.
That shouldn't hold you back, arrays are traversable and sequenceA
would do exactly what you wanted (though quite inefficiently). If it was implemented in folktale, which doesn't feature lists or even a control.applicative
.
control.monad.sequence
should have been working the same as the applicative sequence, but unnecessarily uses chain
instead of ap
. And data.task
is problematic anyway in that ap
is not derivable from chain
with the same semantics.