def add_or_replace_resource(resources, resource):
    """Add a `resource` into `resources` struct, or replace it if already
    present (check via is_same_resource). Edits `resources` in place.

    Returns: True if something changed in resources structure, False
    otherwise
    """
    for i, r in enumerate(resources):
        if resource.is_same_resource(r):
            if r == resource.data:
                return False
            else:
                resources[i] = resource.data
                return True

    # If we didn't return by now, the resource wasn't found, so append it.
    resources.append(resource.data)
    return True