Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return chainRec(T, (next, done, { focus, stack }) => {
while (Pure.is(focus) && stack.length) {
const fn = stack.pop()
focus = fn(focus.a)
}
if (Pure.is(focus)) {
return of(T, done(focus.a))
}
while (Roll.is(focus)) {
// We are mutating `stack` for performance reasons but it's not
// an issue as it's not an observable side effects 8-)
// If we wanted to do same in a staticly typed language,
// some kind of efficient type aligned sequnce should be used.
stack.push(focus.y)
focus = focus.x
}
// here `focus` must be `Lift`
return map((v) => {
if (stack.length === 0) {
return done(v)
}
const fn = stack.pop()
const nextFocus = fn(v)
test('of resolves with the value', function (){
var m = Z.of(Par, 1);
return assertResolved(seq(m), 1);
});
List.prototype[FL.traverse] = function(typeRep, f) {
return this.isNil ?
Z.of (typeRep, Nil) :
Z.ap (Z.map (Cons, f (this.head)), Z.traverse (typeRep, f, this.tail));
};
const foldArg = (node, f, T) => {
if (Pure.is(node)) {
return of(T, node.x)
} else if (Lift.is(node)) {
return f(node.i)
}
}
return chain(a => of(Seq, f(a)), this)
},
({ done, value }) => done ? of(Seq, value) : chainRec(Seq, f, value),
f(chainRecNext, chainRecDone, i)