I have the following function :
def getWayDepthFirst(maze: Maze, position: Position, way: List[Position]): List[List[Position]] = { if (!canWalkOnCell(maze, position)) { Nil } else { if (isExit(position, maze)) { List(position :: way) } else { val explorationArea: List[Position] = List(position.north, position.east, position.south, position.west) filter (x => !way.contains(x) && canWalkOnCell(maze, x)) if (explorationArea.size > 1) { val possibleWays: Future[List[List[List[Position]]]] = Future.traverse(explorationArea)(notYetVisitedPosition => Future(getWayDepthFirst(maze, notYetVisitedPosition, position :: way))) // possibleWays.onSucces() } else { explorationArea.flatMap { ( notYetVisitedPosition => getWayDepthFirst(maze, notYetVisitedPosition, position :: way)) } } } } It should find all the ways through a maze. If there are two or more possible ways that can be search then each of these should be handled in a future.
Now my problem is how to return the result of this. With the Future.traverse I end up with a Future[List[List[List[Position]]]] but what I need is a List[List[Position]].
What is a possibility to return the correct value? And where do I do this? In the onSuccess?