RemoveWhere constructor

RemoveWhere()

Implementation

RemoveWhere()
  : super(
      methodName: "removeWhere",
      targetType: .list,
      arity: 1,
      function: (target, interpreter, arguments) async {
        if (arguments[0] is! ObjClosure) {
          throw RuntimeError("RemoveWhere function must be a function.");
        }
        for (int i = target.length - 1; i >= 0; i--) {
          bool remove =
              await invokeScriptClosure(interpreter, arguments[0], [
                    target[i],
                  ])
                  as bool;
          if (remove) {
            target.removeAt(i);
          }
        }
        return target.length;
      },
    );