combine static method

GroupTracker combine(
  1. Iterable<GroupTracker> trackers
)

Implementation

static GroupTracker combine(Iterable<GroupTracker> trackers) {
  var combinedPositions = <GroupRef, int>{};
  var totalGroupCount = 0;
  var combinedPreviouslyIgnoredRefs = <GroupRef>{};

  for (var tracker in trackers) {
    for (var MapEntry(key: groupRef, value: position) in tracker._positions.entries) {
      if (!combinedPositions.containsKey(groupRef)) {
        combinedPositions[groupRef] = position + totalGroupCount;
      } else {
        throw ArgumentError("""
A GroupRef was reused in multiple places.
This is not allowed since this makes the GroupRef an unreliable reference.
Try using more (unique) GroupRefs or use `recipe.withCapturesIgnored` to discard some."""
        );
      }

      combinedPreviouslyIgnoredRefs.addAll(tracker._previouslyIgnoredRefs);
    }
    totalGroupCount += tracker._groupCount;
  }

  return GroupTracker._create(combinedPositions, totalGroupCount, combinedPreviouslyIgnoredRefs);
}