docs: def merge_csv(filenames: List[str],
                outfile: TextIO = sys.stdout,
                input_dialect: str = 'excel',
                output_dialect: str = 'excel',
                debug: bool = False,
                headers: bool = True) -> None:
      """
      Amalgamate multiple CSV/TSV/similar files into one.
  
      Args:
          filenames: list of filenames to process
          outfile: file-like object to write output to
          input_dialect: dialect of input files, as passed to ``csv.reader``
          output_dialect: dialect to write, as passed to ``csv.writer``
          debug: be verbose?
          headers: do the files have header lines?
      """
      writer = csv.writer(outfile, dialect=output_dialect)
      written_header = False
      header_items = []  # type: List[str]
      for filename in filenames:
          log.info("Processing file " + repr(filename))
          with open(filename, 'r') as f:
              reader = csv.reader(f, dialect=input_dialect)
              if headers:
                  if not written_header:
                      header_items = next(reader)
                      if debug:
                          log.debug("Header row: {!r}", header_items)
                      writer.writerow(header_items)
                      written_header = True
                  else:
                      new_headers = next(reader)
                      if new_headers != header_items:
                          raise ValueError(
                              "Header line in file {filename} doesn't match - "
                              "it was {new} but previous was {old}".format(
                                  filename=repr(filename),
                                  new=repr(new_headers),
                                  old=repr(header_items),
                              ))
                      if debug:
                          log.debug("Header row matches previous")
              else:
                  if debug:
                      log.debug("No headers in use")
              for row in reader:
                  if debug:
                      log.debug("Data row: {!r}", row)
                  writer.writerow(row)