Function
can be an instance of profunctor.
promap
instead of dimap
here yet. https://github.com/flunc/optics/blob/master/src/Internal/Profunctor/Class/Profunctor.js#L9
Function
instance
Map
too.
Promise
s at all?
while (args.length > 0 && !args[0].done)
while (args.length > 0 && !args.every(prop('done')))
every
over each iteration, it could be refactored to something like:function chainRec(f, x) {
var next = function(x) { return {value: x, done: false}; };
var done = function(x) { return {value: x, done: true}; };
var out = [];
var todo = [x];
while (todo.length > 0) {
var xs = f(next, done, todo.shift());
var partitioned = xs.reduce(function(acc, x) {
var bucket = x.done ? acc[1] : acc[0];
bucket.push(x.value);
return acc;
}, [[], []]);
todo.unshift.apply(todo, partitioned[0]);
out.push.apply(out, partitioned[1]);
}
return out;
}
forever
which will repeatedly run the same action sequentially for any given ChainRec
.const forever = m =>
chainRec((next, _, _) => m.map(_ => next(void 0)), void 0);