Added support to BFS and DFS for temprorary lambdas and functors