parameters: (all_values, key_func, merge_func)
return_statement: return res
docstring: Groups all_values by key_func then applies merge_func to the groups.
  
    This takes the all_values list and groups each item in that using the key
    provided by key_func. This produces groups of values with like keys. Thes are
    then handed to the merge_func to produce a new key. If merge_func produces a
    non-None return, it is added to the list of returned values.
docstring_summary: Groups all_values by key_func then applies merge_func to the groups.
docstring_tokens: Groups all_values by key_func then applies merge_func to the groups .
function: def _MergeLikeValuesCommon(all_values, key_func, merge_func):
    """Groups all_values by key_func then applies merge_func to the groups.
  
    This takes the all_values list and groups each item in that using the key
    provided by key_func. This produces groups of values with like keys. Thes are
    then handed to the merge_func to produce a new key. If merge_func produces a
    non-None return, it is added to the list of returned values.
    """
    # When merging, we want to merge values in a consistent order, e.g. so that
    # Scalar(1), Scalar(2) predictably produces ListOfScalarValues([1,2]) rather
    # than 2,1.
    #
    # To do this, the values are sorted by key up front. Then, grouping is
    # performed using a dictionary, but as new groups are found, the order in
    # which they were found is also noted.
    #
    # Merging is then performed on groups in group-creation-order. This ensures
    # that the returned array is in a stable order, group by group.
    #
    # Within a group, the order is stable because of the original sort.
    all_values = list(all_values)
    merge_groups = GroupStably(all_values, key_func)
  
    res = []
    for merge_group in merge_groups:
      v0 = merge_group[0]
      vM = merge_func(v0, merge_group)
      if vM:
        res.append(vM)
    return res
function_tokens: def _MergeLikeValuesCommon ( all_values , key_func , merge_func ) : # When merging, we want to merge values in a consistent order, e.g. so that # Scalar(1), Scalar(2) predictably produces ListOfScalarValues([1,2]) rather # than 2,1. # # To do this, the values are sorted by key up front. Then, grouping is # performed using a dictionary, but as new groups are found, the order in # which they were found is also noted. # # Merging is then performed on groups in group-creation-order. This ensures # that the returned array is in a stable order, group by group. # # Within a group, the order is stable because of the original sort. all_values = list ( all_values ) merge_groups = GroupStably ( all_values , key_func ) res = [ ] for merge_group in merge_groups : v0 = merge_group [ 0 ] vM = merge_func ( v0 , merge_group ) if vM : res . append ( vM ) return res