def depth(self):
    """
    Computes the depth of a diagram by foliating it.

    >>> from discopy.monoidal import *
    >>> x, y = Ty('x'), Ty('y')
    >>> f, g = Box('f', x, y), Box('g', y, x)
    >>> assert Id(x @ y).depth() == 0
    >>> assert f.depth() == 1
    >>> assert (f @ g).depth() == 1
    >>> assert (f >> g).depth() == 2
    """
    *_, slices = self.foliate(yield_slices=True)
    return len(slices)