Fold constructor

Fold()

Implementation

Fold()
  : super(
      methodName: "fold",
      targetType: .list,
      arity: 2,
      function: (target, vm, arguments) async {
        if (arguments[1] is! ObjClosure) {
          throw RuntimeError("Fold function must be a function.");
        }
        var acc = arguments[0];
        for (var element in target) {
          acc = await invokeScriptClosure(vm, arguments[1], [element, acc]);
        }
        return acc;
      },
    );