docs: def _calc_concat_over(datasets, dim, data_vars, coords):
      """
      Determine which dataset variables need to be concatenated in the result,
      and which can simply be taken from the first dataset.
      """
      # Return values
      concat_over = set()
      equals = {}
  
      if dim in datasets[0]:
          concat_over.add(dim)
      for ds in datasets:
          concat_over.update(k for k, v in ds.variables.items()
                             if dim in v.dims)
  
      def process_subset_opt(opt, subset):
          if isinstance(opt, str):
              if opt == 'different':
                  # all nonindexes that are not the same in each dataset
                  for k in getattr(datasets[0], subset):
                      if k not in concat_over:
                          # Compare the variable of all datasets vs. the one
                          # of the first dataset. Perform the minimum amount of
                          # loads in order to avoid multiple loads from disk
                          # while keeping the RAM footprint low.
                          v_lhs = datasets[0].variables[k].load()
                          # We'll need to know later on if variables are equal.
                          computed = []
                          for ds_rhs in datasets[1:]:
                              v_rhs = ds_rhs.variables[k].compute()
                              computed.append(v_rhs)
                              if not v_lhs.equals(v_rhs):
                                  concat_over.add(k)
                                  equals[k] = False
                                  # computed variables are not to be re-computed
                                  # again in the future
                                  for ds, v in zip(datasets[1:], computed):
                                      ds.variables[k].data = v.data
                                  break
                          else:
                              equals[k] = True
  
              elif opt == 'all':
                  concat_over.update(set(getattr(datasets[0], subset)) -
                                     set(datasets[0].dims))
              elif opt == 'minimal':
                  pass
              else:
                  raise ValueError("unexpected value for %s: %s" % (subset, opt))
          else:
              invalid_vars = [k for k in opt
                              if k not in getattr(datasets[0], subset)]
              if invalid_vars:
                  if subset == 'coords':
                      raise ValueError(
                          'some variables in coords are not coordinates on '
                          'the first dataset: %s' % (invalid_vars,))
                  else:
                      raise ValueError(
                          'some variables in data_vars are not data variables '
                          'on the first dataset: %s' % (invalid_vars,))
              concat_over.update(opt)
  
      process_subset_opt(data_vars, 'data_vars')
      process_subset_opt(coords, 'coords')
      return concat_over, equals