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.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 acontrol.applicative
.control.monad.sequence
should have been working the same as the applicative sequence, but unnecessarily useschain
instead ofap
. Anddata.task
is problematic anyway in thatap
is not derivable fromchain
with the same semantics.