mergeBindings function

Map<Variable, Node>? mergeBindings(
  1. Map<Variable, Node>? first,
  2. Map<Variable, Node>? second
)

Implementation

Map<Variable, Node>? mergeBindings(
  Map<Variable, Node>? first,
  Map<Variable, Node>? second,
) {
  if (first == null || second == null) {
    return null;
  }
  final result = newBindings();
  result.addAll(first);
  for (final key in second.keys) {
    final value = second[key]!;
    final other = result[key];
    if (other != null) {
      final subs = other.match(value);
      if (subs == null) {
        return null;
      } else {
        result.addAll(subs);
      }
    } else {
      result[key] = value;
    }
  }
  return result;
}