<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def format_diffindex(diff_index):
 """ Return a JSON formattable representation of a DiffIndex. Returns a generator that returns dictionaries representing the changes. .. code:: [ { 'type': 'A', 'path': 'path/to/added/file.txt', }, { 'type': 'D', 'path': 'path/to/deleted/file.txt', }, { 'type': 'M', 'path': 'path/to/modified/file.txt', }, { 'type': 'R', 'rename_from': 'original/path/to/file.txt', 'rename_to': 'new/path/to/file.txt', }, ] :returns: generator """

    for diff in diff_index:
        if diff.new_file:
            yield format_diff_A(diff)
        elif diff.deleted_file:
            yield format_diff_D(diff)
        elif diff.renamed:
            yield format_diff_R(diff)
        elif diff.a_blob and diff.b_blob and diff.a_blob != diff.b_blob:
            yield format_diff_M(diff)