invertAttributes static method

Map<String, dynamic> invertAttributes(
  1. Map<String, dynamic>? attr,
  2. Map<String, dynamic>? base
)

get anti-attr result base on base

Implementation

static Map<String, dynamic> invertAttributes(
    Map<String, dynamic>? attr, Map<String, dynamic>? base) {
  attr ??= const {};
  base ??= const {};

  var baseInverted = base.keys.fold({}, (dynamic memo, key) {
    if (base![key] != attr![key] && attr.containsKey(key)) {
      memo[key] = base[key];
    }
    return memo;
  });

  var inverted = Map<String, dynamic>.from(attr.keys.fold(baseInverted, (memo, key) {
    if (base![key] != attr![key] && !base.containsKey(key)) {
      memo[key] = null;
    }
    return memo;
  }));
  return inverted;
}