def METHOD_NAME(self, obj, seen, format_callback):
    if obj in seen:
        return []
    seen.add(obj)
    children = []
    for child in self.edges.get(obj, ()):
        children.extend(self.METHOD_NAME(child, seen, format_callback))
    if format_callback:
        ret = [format_callback(obj)]
    else:
        ret = [obj]
    if children:
        ret.append(children)
    return ret