Merge two lists of fields.

    Fields in `b` override fields in `a`. Fields in `a` are output first.

def _merge_fields(a, b):
    """Merge two lists of fields.

    Fields in `b` override fields in `a`. Fields in `a` are output first.
    """

    a_names = set(x[0] for x in a)
    b_names = set(x[0] for x in b)
    a_keep = a_names - b_names

    fields = []

    for name, field in a:
        if name in a_keep:
            fields.append((name, field))

    fields.extend(b)

    return fields