visitThenExpr method
Implementation
@override
Object? visitThenExpr(Expr.Then expr) {
Object? object = evaluate(expr.future);
if (object is Future) {
Stmt.Functional then;
var func = evaluate(expr.then);
if (func is! LoxFunction) {
throw RuntimeError(
expr.name, "Only func can be used as Mapping function");
} else {
then = func.declaration;
}
Environment previous = environment;
return object.then((value) {
if (expr.then is! Expr.Anonymous) {
previous = environment;
}
LoxFunction thenFun = LoxFunction(then, previous, false);
return thenFun.call(this, [value], {});
});
}
throw RuntimeError(expr.name, "Only future can be used in then.");
}