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);
sanctuary
tag on Stack Overflow. You may like to subscribe to it. Also, I posted a question: Custom equality semantics for Immutable.js data structures. I'd love to be able to use maps and sets when working with Sanctuary, but for various reasons neither the native types nor the Immutable.js equivalents are currently suitable.