@classmethod
def collapse_element(cls, overlay, ranges=None, mode='data', backend=None):
    """
        Finds any applicable compositor and applies it.
        """
    from .overlay import Overlay, CompositeOverlay
    unpack = False
    if not isinstance(overlay, CompositeOverlay):
        overlay = Overlay([overlay])
        unpack = True
    prev_ids = tuple()
    while True:
        match = cls.strongest_match(overlay, mode)
        if match is None:
            if unpack and len(overlay) == 1:
                return overlay.values()[0]
            return overlay
        _, applicable_op, (start, stop) = match
        if isinstance(overlay, Overlay):
            values = overlay.values()
            sliced = Overlay(values[start:stop])
        else:
            values = overlay.items()
            sliced = overlay.clone(values[start:stop])
        result = applicable_op.apply(sliced, ranges, backend)
        if applicable_op.group:
            result = result.relabel(group=applicable_op.group)
        if isinstance(overlay, Overlay):
            result = [result]
        else:
            result = list(zip(sliced.keys(), [result]))
        overlay = overlay.clone(values[:start] + result + values[stop:])
        spec_fn = lambda x: not isinstance(x, CompositeOverlay)
        new_ids = tuple(overlay.traverse(lambda x: id(x), [spec_fn]))
        if new_ids == prev_ids:
            return overlay
        prev_ids = new_ids
