'Returns the nearest child which matches an arbitrary predicate lambda
:param predicate: ``lambda element: bool``
:type  predicate: function
:param exclude: ``lambda element: bool`` - excludes matching branches from search
:type  exclude: function, None
:param descend: whether to descend inside matching elements
:type  descend: bool'

def nearest(self, predicate, exclude=None, descend=True):

    r = []
    q = [self]
    while (len(q) > 0):
        e = q.pop(0)
        if (exclude and exclude(e)):
            continue
        if predicate(e):
            r.append(e)
            if ((not descend) and (e is not self)):
                continue
        q.extend(e.children)
    return r
