def _apply_transform_spec(all_rows, transform_spec):
    """Applies transform_spec.func to all rows in all_rows (if func is specified). Removes all fields as specified by
    transform_spec.removed_fields, unless the fields were already deleted by transform_spec.func.

    All modifications are performed in-place.
    """
    if transform_spec.func:
        all_rows = [transform_spec.func(row) for row in all_rows]

    for field_to_remove in transform_spec.removed_fields:
        for row in all_rows:
            if field_to_remove in row:
                del row[field_to_remove]

    return all_rows