ForEach constructor

ForEach()

Implementation

ForEach()
  : super(
      methodName: "forEach",
      targetType: .map,
      arity: 1,
      function: (target, vm, arguments) async {
        if (arguments[0] is! ObjClosure) {
          throw RuntimeError(
            "forEach arg must be a function: (key, value) {...}",
          );
        }
        for (final entry in target.entries) {
          await invokeScriptClosure(vm, arguments[0], [
            entry.key,
            entry.value,
          ]);
        }
        return target.length;
      },
    );