apply method

  1. @override
dynamic apply(
  1. Function function,
  2. List? positionalArguments, [
  3. Map<Symbol, dynamic>? namedArguments
])
override

Applies a function with controlled validation.

Parameters:

  • function: The operation to perform
  • positionalArguments: Positional args
  • namedArguments: Named args

Returns: Sync The result of the operation if validation passes Async A Future that resolves to the result of the operation

Implementation

@override
dynamic apply(Function function, List? positionalArguments, [Map<Symbol, dynamic>? namedArguments]) {

  if (modifiable.contains(function)) {
    try {
      if (test.action(function, this, arguments: (positionalArguments: positionalArguments, namedArguments: namedArguments))) {
        final notification = namedArguments?[#$notification] ?? true;
        final deputy = namedArguments?[#deputy];

        if (function == add) {
          return Function.apply(_add, positionalArguments, {#notification: notification, #deputy: deputy});
        }
        else if (function == addAll) {
          return Function.apply(_addAll, positionalArguments, {#notification: notification, #deputy: deputy});
        }
        else if (function == clear) {
          return Function.apply(_clear, null, {#notification: notification, #deputy: deputy});
        }
        else if (function == remove) {
          return Function.apply(_remove, positionalArguments, {#notification: notification, #deputy: deputy});
        }
        else if (function == removeAll) {
          return Function.apply(_removeAll, positionalArguments, {#notification: notification, #deputy: deputy});
        }
        else if (function == removeWhere) {
          return Function.apply(_removeWhere, positionalArguments, {#notification: notification, #deputy: deputy});
        }
        else if (function == retainAll) {
          return Function.apply(_retainAll, positionalArguments, {#notification: notification, #deputy: deputy});
        }
        else if (function == retainWhere) {
          return Function.apply(_retainWhere, positionalArguments, {#notification: notification, #deputy: deputy});
        }
        return;
      }} catch (_) {}
  }
  return Function.apply(function, positionalArguments, namedArguments);
}